Avoid unnecessary String instantiation in StringUtils.deleteAny()

This commit avoids unnecessary String instantiation in
StringUtils.deleteAny() if nothing was deleted from the
input string.

Closes gh-24924
This commit is contained in:
Johnny Lim 2020-04-18 01:44:16 +09:00 committed by GitHub
parent 87f28ce48e
commit 87fa2c3b97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 0 deletions

View File

@ -461,6 +461,9 @@ public abstract class StringUtils {
result[lastCharIndex++] = c;
}
}
if (lastCharIndex == inString.length()) {
return inString;
}
return new String(result, 0, lastCharIndex);
}