Optimize StringBuilder append for static strings, and as_string().

This commit is contained in:
Lukas Tenbrink 2024-11-28 01:20:58 +01:00
parent f128f383e8
commit 8df2dbe2f6
2 changed files with 10 additions and 8 deletions

View file

@ -68,8 +68,10 @@ String StringBuilder::as_string() const {
int godot_string_elem = 0;
int c_string_elem = 0;
for (int i = 0; i < appended_strings.size(); i++) {
if (appended_strings[i] == -1) {
for (uint32_t i = 0; i < appended_strings.size(); i++) {
const int32_t str_len = appended_strings[i];
if (str_len == -1) {
// Godot string
const String &s = strings[godot_string_elem];
@ -81,11 +83,11 @@ String StringBuilder::as_string() const {
} else {
const char *s = c_strings[c_string_elem];
for (int32_t j = 0; j < appended_strings[i]; j++) {
for (int32_t j = 0; j < str_len; j++) {
buffer[current_position + j] = s[j];
}
current_position += appended_strings[i];
current_position += str_len;
c_string_elem++;
}