Kaynağa Gözat

Optimize `_count` by replacing a full copy with a CoW copy for the full-string count case.

Lukas Tenbrink 8 ay önce
ebeveyn
işleme
b2d881a73a
1 değiştirilmiş dosya ile 2 ekleme ve 4 silme
  1. 2 4
      core/string/ustring.cpp

+ 2 - 4
core/string/ustring.cpp

@@ -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);
 		}
@@ -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);
 		}