Skip to content

Commit

Permalink
Optimize _count by replacing a full copy with a CoW copy for the fu…
Browse files Browse the repository at this point in the history
…ll-string count case.
  • Loading branch information
Ivorforce committed Jan 2, 2025
1 parent 2582793 commit b2d881a
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions core/string/ustring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3707,8 +3707,7 @@ int String::_count(const String &p_string, int p_from, int p_to, bool p_case_ins
return 0;
}
if (p_from == 0 && p_to == len) {
str = String();
str.copy_from_unchecked(&get_data()[0], len);
str = *this;
} else {
str = substr(p_from, p_to - p_from);
}
Expand Down Expand Up @@ -3744,8 +3743,7 @@ int String::_count(const char *p_string, int p_from, int p_to, bool p_case_insen
return 0;
}
if (p_from == 0 && search_limit == source_length) {
str = String();
str.copy_from_unchecked(&get_data()[0], source_length);
str = *this;
} else {
str = substr(p_from, search_limit - p_from);
}
Expand Down

0 comments on commit b2d881a

Please sign in to comment.