Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Unified Diff: third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp

Issue 1563783003: Optimizations to Spellchecking Chunk Generation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp
diff --git a/third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp b/third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp
index 150081b2e5614b391d7f3320d5846bffbd17a871..dc49ff08725d291f096f10f1ab5c8c2e7ec62cfb 100644
--- a/third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp
+++ b/third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp
@@ -479,6 +479,24 @@ void SpellChecker::markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeMask
chunkAndMarkAllMisspellingsAndBadGrammar(textCheckingOptions, fullParagraphToCheck);
}
+static EphemeralRange expandEndToSentenceBoundary(const EphemeralRange& range)
+{
+ ASSERT(range.isNotNull());
+ const VisiblePosition& visibleEnd = createVisiblePosition(range.endPosition());
+ ASSERT(visibleEnd.isNotNull());
+ const Position& sentenceEnd = endOfSentence(visibleEnd).deepEquivalent();
+ return EphemeralRange(range.startPosition(), sentenceEnd.isNotNull() ? sentenceEnd : range.endPosition());
+}
+
+static EphemeralRange expandRangeToSentenceBoundary(const EphemeralRange& range)
+{
+ ASSERT(range.isNotNull());
+ const VisiblePosition& visibleStart = createVisiblePosition(range.startPosition());
+ ASSERT(visibleStart.isNotNull());
+ const Position& sentenceStart = startOfSentence(visibleStart).deepEquivalent();
+ return expandEndToSentenceBoundary(EphemeralRange(sentenceStart.isNull() ? range.startPosition() : sentenceStart, range.endPosition()));
+}
+
void SpellChecker::chunkAndMarkAllMisspellingsAndBadGrammar(Node* node)
{
TRACE_EVENT0("blink", "SpellChecker::chunkAndMarkAllMisspellingsAndBadGrammar");
@@ -493,42 +511,29 @@ void SpellChecker::chunkAndMarkAllMisspellingsAndBadGrammar(TextCheckingTypeMask
{
if (fullParagraphToCheck.isEmpty())
return;
+ const EphemeralRange& paragraphRange = fullParagraphToCheck.paragraphRange();
// Since the text may be quite big chunk it up and adjust to the sentence boundary.
const int kChunkSize = 16 * 1024;
- int start = fullParagraphToCheck.checkingStart();
- int end = fullParagraphToCheck.checkingEnd();
- start = std::min(start, end);
- end = std::max(start, end);
- const int kNumChunksToCheck = (end - start + kChunkSize - 1) / kChunkSize;
- int currentChunkStart = start;
- if (kNumChunksToCheck == 1) {
- EphemeralRange checkRange = fullParagraphToCheck.checkingRange();
- markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, checkRange, checkRange, 0);
- return;
- }
-
- for (int iter = 0; iter < kNumChunksToCheck; ++iter) {
- EphemeralRange checkRange = expandRangeToSentenceBoundary(fullParagraphToCheck.subrange(currentChunkStart, kChunkSize));
- int checkingLength = 0;
- markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, checkRange, checkRange, iter, &checkingLength);
- currentChunkStart += checkingLength;
+ CharacterIterator checkRangeIterator(fullParagraphToCheck.checkingRange(), TextIteratorEmitsObjectReplacementCharacter);
+ for (int requestNum = 0; !checkRangeIterator.atEnd(); requestNum++) {
+ EphemeralRange chunkRange = checkRangeIterator.calculateCharacterSubrange(0, kChunkSize);
+ EphemeralRange checkRange = requestNum ? expandEndToSentenceBoundary(chunkRange) : expandRangeToSentenceBoundary(chunkRange);
+
+ RefPtrWillBeRawPtr<SpellCheckRequest> request = SpellCheckRequest::create(resolveTextCheckingTypeMask(textCheckingOptions), TextCheckingProcessBatch, checkRange, paragraphRange, requestNum);
+ if (request)
+ m_spellCheckRequester->requestCheckingFor(request);
+
+ if (!checkRangeIterator.atEnd()) {
+ checkRangeIterator.advance(1);
+ // The layout should be already update due to the initialization of checkRangeIterator,
+ // so comparePositions can be directly called.
+ if (comparePositions(chunkRange.endPosition(), checkRange.endPosition()) < 0)
+ checkRangeIterator.advance(TextIterator::rangeLength(chunkRange.endPosition(), checkRange.endPosition()));
+ }
}
}
-void SpellChecker::markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeMask textCheckingOptions, const EphemeralRange& checkRange, const EphemeralRange& paragraphRange, int requestNumber, int* checkingLength)
-{
- TextCheckingParagraph sentenceToCheck(checkRange, paragraphRange);
- if (checkingLength)
- *checkingLength = sentenceToCheck.checkingLength();
-
- RefPtrWillBeRawPtr<SpellCheckRequest> request = SpellCheckRequest::create(resolveTextCheckingTypeMask(textCheckingOptions), TextCheckingProcessBatch, checkRange, paragraphRange, requestNumber);
- if (!request)
- return;
-
- m_spellCheckRequester->requestCheckingFor(request);
-}
-
void SpellChecker::markAndReplaceFor(PassRefPtrWillBeRawPtr<SpellCheckRequest> request, const Vector<TextCheckingResult>& results)
{
TRACE_EVENT0("blink", "SpellChecker::markAndReplaceFor");

Powered by Google App Engine
This is Rietveld 408576698