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

Loading…
Cancel
Save