Skip to content

Commit 884cbb5

Browse files
committed
Don't repeat calls to strlen in split, and make splitter_length const in get_slice.
1 parent f128f38 commit 884cbb5

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

core/string/ustring.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,7 @@ String String::get_slice(const char *p_splitter, int p_slice) const {
12781278
}
12791279

12801280
int i = 0;
1281-
int splitter_length = strlen(p_splitter);
1281+
const int splitter_length = strlen(p_splitter);
12821282
while (true) {
12831283
pos = find(p_splitter, pos);
12841284
if (pos == -1) {
@@ -1429,6 +1429,7 @@ Vector<String> String::split(const char *p_splitter, bool p_allow_empty, int p_m
14291429

14301430
int from = 0;
14311431
int len = length();
1432+
const int splitter_length = strlen(p_splitter);
14321433

14331434
while (true) {
14341435
int end;
@@ -1459,7 +1460,7 @@ Vector<String> String::split(const char *p_splitter, bool p_allow_empty, int p_m
14591460
break;
14601461
}
14611462

1462-
from = end + strlen(p_splitter);
1463+
from = end + splitter_length;
14631464
}
14641465

14651466
return ret;

0 commit comments

Comments
 (0)