mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +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:
parent
a40fc2354a
commit
76af9537ed
1 changed files with 5 additions and 6 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue