You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
Avoid single character String allocations when appending characters
Removed calls to String::chr() when appending characters to Strings in Expression, Resource, and VariantParser, to avoid creating temporary Strings for each character. Also updated the Resource case to resize String up front, since size is known.
This commit is contained in:
@@ -142,15 +142,18 @@ String Resource::generate_scene_unique_id() {
|
||||
static constexpr uint32_t char_count = ('z' - 'a');
|
||||
static constexpr uint32_t base = char_count + ('9' - '0');
|
||||
String id;
|
||||
id.resize(characters + 1);
|
||||
char32_t *ptr = id.ptrw();
|
||||
for (uint32_t i = 0; i < characters; i++) {
|
||||
uint32_t c = random_num % base;
|
||||
if (c < char_count) {
|
||||
id += String::chr('a' + c);
|
||||
ptr[i] = ('a' + c);
|
||||
} else {
|
||||
id += String::chr('0' + (c - char_count));
|
||||
ptr[i] = ('0' + (c - char_count));
|
||||
}
|
||||
random_num /= base;
|
||||
}
|
||||
ptr[characters] = '\0';
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user