From 34b2f7174ba187d99dfb8704b9cf19d369accc13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= Date: Wed, 16 Mar 2022 10:54:03 +0100 Subject: [PATCH] do not reset useful cache to empty in populateNear() --- icu4c/source/common/rbbi_cache.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/icu4c/source/common/rbbi_cache.cpp b/icu4c/source/common/rbbi_cache.cpp index 26d82df781..54a77c97c6 100644 --- a/icu/source/common/rbbi_cache.cpp +++ b/icu/source/common/rbbi_cache.cpp @@ -352,7 +352,7 @@ UBool RuleBasedBreakIterator::BreakCache if ((position < fBoundaries[fStartBufIdx] - 15) || position > (fBoundaries[fEndBufIdx] + 15)) { int32_t aBoundary = 0; int32_t ruleStatusIndex = 0; - if (position > 20) { + if (position > 20 && false) { // handleSafePrevious() is broken and always returns 0 int32_t backupPos = fBI->handleSafePrevious(position); if (backupPos > 0) { @@ -376,7 +376,10 @@ UBool RuleBasedBreakIterator::BreakCache::populateNear(int32_t position, UErrorC ruleStatusIndex = fBI->fRuleStatusIndex; } } - reset(aBoundary, ruleStatusIndex); // Reset cache to hold aBoundary as a single starting point. + // Reset cache to hold aBoundary as a single starting point. + // Do not do so if what's in the cache is still more useful than an empty cache. + if (!(aBoundary == 0 && position > fBoundaries[fEndBufIdx])) + reset(aBoundary, ruleStatusIndex); } // Fill in boundaries between existing cache content and the new requested position. -- 2.34.1