Merge pull request #99893 from kiroxas/avoidUTF8ParsingWhenNotNecessary

Avoid duplicated `utf8()` calls
This commit is contained in:
Rémi Verschelde 2025-01-06 22:47:12 +01:00
commit e06cac212b
No known key found for this signature in database
GPG key ID: C3336907360768E1
3 changed files with 11 additions and 7 deletions

View file

@ -198,11 +198,12 @@ Error PCKPacker::flush(bool p_verbose) {
}
for (int i = 0; i < files.size(); i++) {
int string_len = files[i].path.utf8().length();
CharString utf8_string = files[i].path.utf8();
int string_len = utf8_string.length();
int pad = _get_pad(4, string_len);
fhead->store_32(uint32_t(string_len + pad));
fhead->store_buffer((const uint8_t *)files[i].path.utf8().get_data(), string_len);
fhead->store_buffer((const uint8_t *)utf8_string.get_data(), string_len);
for (int j = 0; j < pad; j++) {
fhead->store_8(0);
}

View file

@ -8256,11 +8256,10 @@ PackedByteArray GLTFDocument::_serialize_glb_buffer(Ref<GLTFState> p_state, Erro
const int32_t header_size = 12;
const int32_t chunk_header_size = 8;
int32_t padding = (chunk_header_size + json.utf8().length()) % 4;
json += String(" ").repeat(padding);
CharString cs = json.utf8();
const uint32_t text_chunk_length = cs.length();
int32_t padding = (chunk_header_size + cs.length()) % 4;
const uint32_t text_chunk_length = cs.length() + padding;
const uint32_t text_chunk_type = 0x4E4F534A; //JSON
int32_t binary_data_length = 0;
@ -8278,6 +8277,9 @@ PackedByteArray GLTFDocument::_serialize_glb_buffer(Ref<GLTFState> p_state, Erro
buffer->put_32(text_chunk_length);
buffer->put_32(text_chunk_type);
buffer->put_data((uint8_t *)&cs[0], cs.length());
for (int i = 0; i < padding; i++) {
buffer->put_8(' ');
}
if (binary_chunk_length) {
buffer->put_32(binary_chunk_length);
buffer->put_32(binary_chunk_type);

View file

@ -1975,7 +1975,8 @@ void DisplayServerX11::window_set_title(const String &p_title, WindowID p_window
Atom _net_wm_name = XInternAtom(x11_display, "_NET_WM_NAME", false);
Atom utf8_string = XInternAtom(x11_display, "UTF8_STRING", false);
if (_net_wm_name != None && utf8_string != None) {
XChangeProperty(x11_display, wd.x11_window, _net_wm_name, utf8_string, 8, PropModeReplace, (unsigned char *)p_title.utf8().get_data(), p_title.utf8().length());
CharString utf8_title = p_title.utf8();
XChangeProperty(x11_display, wd.x11_window, _net_wm_name, utf8_string, 8, PropModeReplace, (unsigned char *)utf8_title.get_data(), utf8_title.length());
}
}