Browse Source

Merge pull request #332 in CORE/base-third from final/10.0 to bugfix/10.0

* commit 'edf73060f07475f52f03aa81cf9d3769f5e107af':
  REPORT-23612 【性能插件】国际换行功能性能问题
bugfix/10.0
Harrison 5 years ago
parent
commit
a8db816445
  1. 28
      fine-icu4j/src/com/fr/third/ibm/icu/text/RuleBasedBreakIterator.java

28
fine-icu4j/src/com/fr/third/ibm/icu/text/RuleBasedBreakIterator.java

@ -17,6 +17,7 @@ import java.nio.ByteBuffer;
import java.text.CharacterIterator;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import com.fr.third.ibm.icu.impl.CharacterIteration;
import com.fr.third.ibm.icu.impl.ICUBinary;
@ -43,8 +44,11 @@ public class RuleBasedBreakIterator extends BreakIterator {
*/
private RuleBasedBreakIterator() {
fDictionaryCharCount = 0;
synchronized(gAllBreakEngines) {
try {
rLock.lock();
fBreakEngines = new ArrayList<LanguageBreakEngine>(gAllBreakEngines);
} finally {
rLock.unlock();
}
}
@ -131,8 +135,11 @@ public class RuleBasedBreakIterator extends BreakIterator {
if (fText != null) {
result.fText = (CharacterIterator)(fText.clone());
}
synchronized (gAllBreakEngines) {
try {
rLock.lock();
result.fBreakEngines = new ArrayList<LanguageBreakEngine>(gAllBreakEngines);
} finally {
rLock.unlock();
}
result.fLookAheadMatches = new LookAheadResults();
result.fBreakCache = result.new BreakCache(fBreakCache);
@ -294,10 +301,19 @@ public class RuleBasedBreakIterator extends BreakIterator {
*/
private static final List<LanguageBreakEngine> gAllBreakEngines;
private static final ReentrantReadWriteLock rwLock;
private static final ReentrantReadWriteLock.ReadLock rLock;
private static final ReentrantReadWriteLock.WriteLock wLock;
static {
gUnhandledBreakEngine = new UnhandledBreakEngine();
gAllBreakEngines = new ArrayList<LanguageBreakEngine>();
gAllBreakEngines.add(gUnhandledBreakEngine);
rwLock = new ReentrantReadWriteLock();
rLock = rwLock.readLock();
wLock = rwLock.writeLock();
}
/**
@ -663,7 +679,8 @@ public class RuleBasedBreakIterator extends BreakIterator {
}
}
synchronized (gAllBreakEngines) {
try {
wLock.lock();
// This break iterator's list of break engines didn't handle the character.
// Check the global list, another break iterator may have instantiated the
// desired engine.
@ -717,7 +734,10 @@ public class RuleBasedBreakIterator extends BreakIterator {
fBreakEngines.add(eng);
}
return eng;
} // end synchronized(gAllBreakEngines)
// end synchronized(gAllBreakEngines)
} finally {
wLock.unlock();
}
}
private static final int kMaxLookaheads = 8;

Loading…
Cancel
Save