Merge pull request #145 from DevFactory/release/value-of-and-double-check-fix-1
Fixing the use of inefficient Number Constructor and Double check
This commit is contained in:
commit
c8f4d59f13
@ -115,7 +115,7 @@ class DictSegment implements Comparable<DictSegment>{
|
||||
//设置hit的当前处理位置
|
||||
searchHit.setEnd(begin);
|
||||
|
||||
Character keyChar = new Character(charArray[begin]);
|
||||
Character keyChar = Character.valueOf(charArray[begin]);
|
||||
DictSegment ds = null;
|
||||
|
||||
//引用实例变量为本地变量,避免查询时遇到更新的同步问题
|
||||
@ -187,7 +187,7 @@ class DictSegment implements Comparable<DictSegment>{
|
||||
*/
|
||||
private synchronized void fillSegment(char[] charArray , int begin , int length , int enabled){
|
||||
//获取字典表中的汉字对象
|
||||
Character beginChar = new Character(charArray[begin]);
|
||||
Character beginChar = Character.valueOf(charArray[begin]);
|
||||
Character keyChar = charMap.get(beginChar);
|
||||
//字典中没有该字,则将其添加入字典
|
||||
if(keyChar == null){
|
||||
@ -280,13 +280,11 @@ class DictSegment implements Comparable<DictSegment>{
|
||||
* 线程同步方法
|
||||
*/
|
||||
private DictSegment[] getChildrenArray(){
|
||||
if(this.childrenArray == null){
|
||||
synchronized(this){
|
||||
if(this.childrenArray == null){
|
||||
this.childrenArray = new DictSegment[ARRAY_LENGTH_LIMIT];
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.childrenArray;
|
||||
}
|
||||
|
||||
@ -295,13 +293,11 @@ class DictSegment implements Comparable<DictSegment>{
|
||||
* 线程同步方法
|
||||
*/
|
||||
private Map<Character , DictSegment> getChildrenMap(){
|
||||
if(this.childrenMap == null){
|
||||
synchronized(this){
|
||||
if(this.childrenMap == null){
|
||||
this.childrenMap = new ConcurrentHashMap<Character, DictSegment>(ARRAY_LENGTH_LIMIT * 2,0.8f);
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.childrenMap;
|
||||
}
|
||||
|
||||
|
@ -103,7 +103,7 @@ public class Dictionary {
|
||||
* @return Dictionary
|
||||
*/
|
||||
public static synchronized Dictionary initial(Configuration cfg){
|
||||
if(singleton == null){
|
||||
|
||||
synchronized(Dictionary.class){
|
||||
if(singleton == null){
|
||||
singleton = new Dictionary();
|
||||
@ -127,7 +127,6 @@ public class Dictionary {
|
||||
return singleton;
|
||||
}
|
||||
}
|
||||
}
|
||||
return singleton;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user