Browse Source

REPORT-23612 【性能插件】国际换行功能性能问题

release/10.0
Hugh.C 5 years ago
parent
commit
b253560503
  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