Skip to content

Commit

Permalink
Avoid substring allocation in StringUtils.replace
Browse files Browse the repository at this point in the history
Closes gh-24023
  • Loading branch information
jhoeller committed Nov 19, 2019
1 parent 85471d0 commit 268d029
Showing 1 changed file with 2 additions and 2 deletions.
Expand Up @@ -417,14 +417,14 @@ public static String replace(String inString, String oldPattern, @Nullable Strin
int pos = 0; // our position in the old string
int patLen = oldPattern.length();
while (index >= 0) {
sb.append(inString.substring(pos, index));
sb.append(inString, pos, index);
sb.append(newPattern);
pos = index + patLen;
index = inString.indexOf(oldPattern, pos);
}

// append any characters to the right of a match
sb.append(inString.substring(pos));
sb.append(inString, pos, inString.length());
return sb.toString();
}

Expand Down

0 comments on commit 268d029

Please sign in to comment.