1
0
Fork 0

Merge pull request #100295 from Ivorforce/string-builder-inplace

Optimize `StringBuilder.as_string` by constructing the string in-place and skipping unnecessary checks.
This commit is contained in:
Rémi Verschelde 2024-12-12 14:10:21 +01:00
commit 7b15c0622e
No known key found for this signature in database
GPG Key ID: C3336907360768E1
1 changed files with 5 additions and 6 deletions

View File

@ -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;
}