You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
Optimize StringBuilder.as_string by constructing the string in-place and skipping unnecessary checks.
Co-authored-by: YYF233333 <nbyyf2002@mail.ustc.edu.cn>
This commit is contained in:
@@ -61,7 +61,9 @@ String StringBuilder::as_string() const {
|
||||
return "";
|
||||
}
|
||||
|
||||
char32_t *buffer = memnew_arr(char32_t, string_length);
|
||||
String string;
|
||||
string.resize(string_length + 1);
|
||||
char32_t *buffer = string.ptrw();
|
||||
|
||||
int current_position = 0;
|
||||
|
||||
@@ -92,10 +94,7 @@ String StringBuilder::as_string() const {
|
||||
c_string_elem++;
|
||||
}
|
||||
}
|
||||
buffer[current_position] = 0;
|
||||
|
||||
String final_string = String(buffer, string_length);
|
||||
|
||||
memdelete_arr(buffer);
|
||||
|
||||
return final_string;
|
||||
return string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user