Skip to content

Commit

Permalink
Merge pull request #99817 from Ivorforce/strlen-char32_t
Browse files Browse the repository at this point in the history
Use `strlen()` 3 times instead of custom length check implementations in ustring
  • Loading branch information
Repiteo committed Dec 5, 2024
2 parents 8e01601 + 2b39314 commit 45734bd
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions core/string/ustring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ const char16_t Char16String::_null = 0;
const char32_t String::_null = 0;
const char32_t String::_replacement_char = 0xfffd;

// strlen equivalent function for char32_t * arguments.
_FORCE_INLINE_ size_t strlen(const char32_t *p_str) {
const char32_t *ptr = p_str;
while (*ptr != 0) {
++ptr;
}
return ptr - p_str;
}

bool select_word(const String &p_s, int p_col, int &r_beg, int &r_end) {
const String &s = p_s;
int beg = CLAMP(p_col, 0, s.length());
Expand Down Expand Up @@ -424,11 +433,7 @@ void String::copy_from(const char32_t *p_cstr) {
return;
}

int len = 0;
const char32_t *ptr = p_cstr;
while (*(ptr++) != 0) {
len++;
}
const int len = strlen(p_cstr);

if (len == 0) {
resize(0);
Expand Down Expand Up @@ -629,12 +634,7 @@ String &String::operator+=(char32_t p_char) {

bool String::operator==(const char *p_str) const {
// compare Latin-1 encoded c-string
int len = 0;
const char *aux = p_str;

while (*(aux++) != 0) {
len++;
}
int len = strlen(p_str);

if (length() != len) {
return false;
Expand Down Expand Up @@ -668,12 +668,7 @@ bool String::operator==(const wchar_t *p_str) const {
}

bool String::operator==(const char32_t *p_str) const {
int len = 0;
const char32_t *aux = p_str;

while (*(aux++) != 0) {
len++;
}
const int len = strlen(p_str);

if (length() != len) {
return false;
Expand Down

0 comments on commit 45734bd

Please sign in to comment.