Просмотр исходного кода

Remove duplicate `utf8()` calls

Kiro 8 месяцев назад
Родитель
Сommit
06efe84bca
3 измененных файлов с 11 добавлено и 7 удалено
  1. 3 2
      core/io/pck_packer.cpp
  2. 6 4
      modules/gltf/gltf_document.cpp
  3. 2 1
      platform/linuxbsd/x11/display_server_x11.cpp

+ 3 - 2
core/io/pck_packer.cpp

@@ -198,11 +198,12 @@ Error PCKPacker::flush(bool p_verbose) {
 	}
 	}
 
 
 	for (int i = 0; i < files.size(); i++) {
 	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);
 		int pad = _get_pad(4, string_len);
 
 
 		fhead->store_32(uint32_t(string_len + pad));
 		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++) {
 		for (int j = 0; j < pad; j++) {
 			fhead->store_8(0);
 			fhead->store_8(0);
 		}
 		}

+ 6 - 4
modules/gltf/gltf_document.cpp

@@ -8235,11 +8235,10 @@ PackedByteArray GLTFDocument::_serialize_glb_buffer(Ref<GLTFState> p_state, Erro
 	const int32_t header_size = 12;
 	const int32_t header_size = 12;
 	const int32_t chunk_header_size = 8;
 	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();
 	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
 	const uint32_t text_chunk_type = 0x4E4F534A; //JSON
 	int32_t binary_data_length = 0;
 	int32_t binary_data_length = 0;
@@ -8257,6 +8256,9 @@ PackedByteArray GLTFDocument::_serialize_glb_buffer(Ref<GLTFState> p_state, Erro
 	buffer->put_32(text_chunk_length);
 	buffer->put_32(text_chunk_length);
 	buffer->put_32(text_chunk_type);
 	buffer->put_32(text_chunk_type);
 	buffer->put_data((uint8_t *)&cs[0], cs.length());
 	buffer->put_data((uint8_t *)&cs[0], cs.length());
+	for (int i = 0; i < padding; i++) {
+		buffer->put_8(' ');
+	}
 	if (binary_chunk_length) {
 	if (binary_chunk_length) {
 		buffer->put_32(binary_chunk_length);
 		buffer->put_32(binary_chunk_length);
 		buffer->put_32(binary_chunk_type);
 		buffer->put_32(binary_chunk_type);

+ 2 - 1
platform/linuxbsd/x11/display_server_x11.cpp

@@ -1939,7 +1939,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 _net_wm_name = XInternAtom(x11_display, "_NET_WM_NAME", false);
 	Atom utf8_string = XInternAtom(x11_display, "UTF8_STRING", false);
 	Atom utf8_string = XInternAtom(x11_display, "UTF8_STRING", false);
 	if (_net_wm_name != None && utf8_string != None) {
 	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());
 	}
 	}
 }
 }