Skip to content

Commit bbd6dbb

Browse files
l46kokcopybara-github
authored andcommitted
Optimize parsing a large string literal by avoiding making substring copies
PiperOrigin-RevId: 612976307
1 parent af32065 commit bbd6dbb

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

common/src/main/java/dev/cel/common/internal/Constants.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,15 @@ private static void checkForClosingQuote(String text, String quote) throws Parse
497497
while (position + quote.length() <= text.length()) {
498498
char codeUnit = text.charAt(position);
499499
if (codeUnit != '\\') {
500-
if (text.substring(position).startsWith(quote)) {
500+
boolean quoteMatches = true;
501+
for (int i = 0; i < quote.length(); i++) {
502+
if (text.charAt(position + i) != quote.charAt(i)) {
503+
quoteMatches = false;
504+
break;
505+
}
506+
}
507+
508+
if (quoteMatches) {
501509
isClosed = position + quote.length() == text.length();
502510
break;
503511
}

0 commit comments

Comments
 (0)