提交 8f08cb90 authored 作者: S.Vladykin's avatar S.Vladykin

Relaxed synchronization on CompareMode.getInstance.

上级 86f06728
...@@ -47,7 +47,7 @@ public class CompareMode { ...@@ -47,7 +47,7 @@ public class CompareMode {
*/ */
public static final String UNSIGNED = "UNSIGNED"; public static final String UNSIGNED = "UNSIGNED";
private static CompareMode lastUsed; private static volatile CompareMode lastUsed;
private static final boolean CAN_USE_ICU4J; private static final boolean CAN_USE_ICU4J;
...@@ -86,8 +86,7 @@ public class CompareMode { ...@@ -86,8 +86,7 @@ public class CompareMode {
* @param strength the collation strength * @param strength the collation strength
* @return the compare mode * @return the compare mode
*/ */
public static synchronized CompareMode getInstance(String name, public static CompareMode getInstance(String name, int strength) {
int strength) {
return getInstance(name, strength, SysProperties.SORT_BINARY_UNSIGNED); return getInstance(name, strength, SysProperties.SORT_BINARY_UNSIGNED);
} }
...@@ -102,17 +101,18 @@ public class CompareMode { ...@@ -102,17 +101,18 @@ public class CompareMode {
* @param binaryUnsigned whether to compare binaries as unsigned * @param binaryUnsigned whether to compare binaries as unsigned
* @return the compare mode * @return the compare mode
*/ */
public static synchronized CompareMode getInstance(String name, public static CompareMode getInstance(String name, int strength, boolean binaryUnsigned) {
int strength, boolean binaryUnsigned) { CompareMode last;
if (lastUsed != null) {
if (StringUtils.equals(lastUsed.name, name) && if ((last = lastUsed) != null) {
lastUsed.strength == strength && if (StringUtils.equals(last.name, name) &&
lastUsed.binaryUnsigned == binaryUnsigned) { last.strength == strength &&
return lastUsed; last.binaryUnsigned == binaryUnsigned) {
return last;
} }
} }
if (name == null || name.equals(OFF)) { if (name == null || name.equals(OFF)) {
lastUsed = new CompareMode(name, strength, binaryUnsigned); lastUsed = last = new CompareMode(name, strength, binaryUnsigned);
} else { } else {
boolean useICU4J; boolean useICU4J;
if (name.startsWith(ICU4J)) { if (name.startsWith(ICU4J)) {
...@@ -125,12 +125,12 @@ public class CompareMode { ...@@ -125,12 +125,12 @@ public class CompareMode {
useICU4J = CAN_USE_ICU4J; useICU4J = CAN_USE_ICU4J;
} }
if (useICU4J) { if (useICU4J) {
lastUsed = new CompareModeIcu4J(name, strength, binaryUnsigned); lastUsed = last = new CompareModeIcu4J(name, strength, binaryUnsigned);
} else { } else {
lastUsed = new CompareModeDefault(name, strength, binaryUnsigned); lastUsed = last = new CompareModeDefault(name, strength, binaryUnsigned);
} }
} }
return lastUsed; return last;
} }
/** /**
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论