[LANG-1679] Improve performance of StringUtils.unwrap(String, String) (#844)

This commit is contained in:
cloverandwang 2022-04-03 22:20:34 +08:00 committed by GitHub
parent 97e1f091af
commit 944608b854
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9425,13 +9425,7 @@ public static String unwrap(final String str, final String wrapToken) {
}
if (startsWith(str, wrapToken) && endsWith(str, wrapToken)) {
final int startIndex = str.indexOf(wrapToken);
final int endIndex = str.lastIndexOf(wrapToken);
final int wrapLength = wrapToken.length();
if (startIndex != -1 && endIndex != -1) {
return str.substring(startIndex + wrapLength, endIndex);
}
return str.substring(wrapToken.length(), str.lastIndexOf(wrapToken));
}
return str;