Unverified 提交 c4240183 authored 作者: Turbanov Andrey's avatar Turbanov Andrey 提交者: GitHub

cleanup StringUtils.cache

1. No need to call `hashCode` if  `cache=null`
2. Remove redundant `null` comparison. `String.equals` will anyway return `false`
上级 c5652260
...@@ -941,16 +941,14 @@ public class StringUtils { ...@@ -941,16 +941,14 @@ public class StringUtils {
} else if (s.isEmpty()) { } else if (s.isEmpty()) {
return ""; return "";
} }
int hash = s.hashCode();
String[] cache = getCache(); String[] cache = getCache();
if (cache != null) { if (cache != null) {
int hash = s.hashCode();
int index = hash & (SysProperties.OBJECT_CACHE_SIZE - 1); int index = hash & (SysProperties.OBJECT_CACHE_SIZE - 1);
String cached = cache[index]; String cached = cache[index];
if (cached != null) {
if (s.equals(cached)) { if (s.equals(cached)) {
return cached; return cached;
} }
}
cache[index] = s; cache[index] = s;
} }
return s; return s;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论