Skip to content

Commit 8eda0ea

Browse files
lauraharkercopybara-github
authored andcommitted
Remove unnecessary String.split calls in StripCode
This is a slight performance improvement. PiperOrigin-RevId: 704434673
1 parent 6132e47 commit 8eda0ea

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/com/google/javascript/jscomp/StripCode.java

+17-8
Original file line numberDiff line numberDiff line change
@@ -745,17 +745,26 @@ boolean nameIncludesFieldNameToStrip(@Nullable Node n) {
745745
String nameString = n.getString();
746746
// CollapseProperties may have turned "a.b.c" into "a$b$c",
747747
// so split that up and match its parts.
748-
if (nameString.indexOf('$') != -1) {
749-
for (String part : nameString.split("\\$")) {
750-
if (isStripName(part)) {
751-
return true;
752-
}
748+
int end = nameString.indexOf('$');
749+
if (end == -1) {
750+
return false;
751+
}
752+
// iterate over all the $-deliminated parts of the name, where each part is from [start,end)
753+
int start = 0;
754+
while (true) {
755+
if (isStripName(nameString.substring(start, end))) {
756+
return true;
757+
}
758+
if (end == nameString.length()) {
759+
break;
753760
}
761+
int newStart = end + 1;
762+
int newEnd = nameString.indexOf('$', newStart);
763+
start = newStart;
764+
end = newEnd == -1 ? nameString.length() : newEnd;
754765
}
755-
return false;
756-
} else {
757-
return false;
758766
}
767+
return false;
759768
}
760769

761770
/**

0 commit comments

Comments
 (0)