Merge pull request #100314 from Ivorforce/use-string-chr

Optimize `String::chr` to avoid calling `strlen`. Use `String::chr` instead of `String(&chr, 1)` where appropriate.
This commit is contained in:
Thaddeus Crews 2025-03-13 08:57:20 -05:00
commit e97bb76142
No known key found for this signature in database
GPG key ID: 62181B86FE9E5D84
4 changed files with 8 additions and 11 deletions

View file

@ -1603,11 +1603,6 @@ String String::to_lower() const {
return lower;
}
String String::chr(char32_t p_char) {
char32_t c[2] = { p_char, 0 };
return String(c);
}
String String::num(double p_num, int p_decimals) {
if (Math::is_nan(p_num)) {
return "nan";

View file

@ -434,7 +434,11 @@ public:
static String num_real(float p_num, bool p_trailing = true);
static String num_int64(int64_t p_num, int base = 10, bool capitalize_hex = false);
static String num_uint64(uint64_t p_num, int base = 10, bool capitalize_hex = false);
static String chr(char32_t p_char);
static String chr(char32_t p_char) {
String string;
string.parse_utf32(p_char);
return string;
}
static String md5(const uint8_t *p_md5);
static String hex_encode_buffer(const uint8_t *p_buffer, int p_len);
Vector<uint8_t> hex_decode() const;