字符串为空时,直接复用全局的静态final EMPTY字段,而不需要调用toString方法

This commit is contained in:
echohlne 2020-07-06 00:17:34 +08:00
parent a0f5970037
commit 1ad1451a86

View File

@ -1840,7 +1840,7 @@ public class StrUtil {
*/
public static String subBefore(CharSequence string, char separator, boolean isLastSeparator) {
if (isEmpty(string)) {
return null == string ? null : string.toString();
return null == string ? null : EMPTY;
}
final String str = string.toString();
@ -1878,7 +1878,7 @@ public class StrUtil {
*/
public static String subAfter(CharSequence string, CharSequence separator, boolean isLastSeparator) {
if (isEmpty(string)) {
return null == string ? null : string.toString();
return null == string ? null : EMPTY;
}
if (separator == null) {
return EMPTY;
@ -1914,7 +1914,7 @@ public class StrUtil {
*/
public static String subAfter(CharSequence string, char separator, boolean isLastSeparator) {
if (isEmpty(string)) {
return null == string ? null : string.toString();
return null == string ? null : EMPTY;
}
final String str = string.toString();
final int pos = isLastSeparator ? str.lastIndexOf(separator) : str.indexOf(separator);