Skip to content

Commit

Permalink
Remove unnecessary String.split calls in StripCode
Browse files Browse the repository at this point in the history
This is a slight performance improvement.

PiperOrigin-RevId: 704434673
  • Loading branch information
lauraharker authored and copybara-github committed Dec 9, 2024
1 parent 6132e47 commit 8eda0ea
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/com/google/javascript/jscomp/StripCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -745,17 +745,26 @@ boolean nameIncludesFieldNameToStrip(@Nullable Node n) {
String nameString = n.getString();
// CollapseProperties may have turned "a.b.c" into "a$b$c",
// so split that up and match its parts.
if (nameString.indexOf('$') != -1) {
for (String part : nameString.split("\\$")) {
if (isStripName(part)) {
return true;
}
int end = nameString.indexOf('$');
if (end == -1) {
return false;
}
// iterate over all the $-deliminated parts of the name, where each part is from [start,end)
int start = 0;
while (true) {
if (isStripName(nameString.substring(start, end))) {
return true;
}
if (end == nameString.length()) {
break;
}
int newStart = end + 1;
int newEnd = nameString.indexOf('$', newStart);
start = newStart;
end = newEnd == -1 ? nameString.length() : newEnd;
}
return false;
} else {
return false;
}
return false;
}

/**
Expand Down

0 comments on commit 8eda0ea

Please sign in to comment.