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

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

Issue 1369713002: Avoid creating duplicate Range objects when handling misspellings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: compile fix Created 5 years, 3 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/SpellCheckRequester.cpp
diff --git a/third_party/WebKit/Source/core/editing/spellcheck/SpellCheckRequester.cpp b/third_party/WebKit/Source/core/editing/spellcheck/SpellCheckRequester.cpp
index acdea4597f8967f6609b5699ebd750859fa50932..2e982175360ecfdf189a1d33a81aef0501b46947 100644
--- a/third_party/WebKit/Source/core/editing/spellcheck/SpellCheckRequester.cpp
+++ b/third_party/WebKit/Source/core/editing/spellcheck/SpellCheckRequester.cpp
@@ -67,25 +67,38 @@ DEFINE_TRACE(SpellCheckRequest)
TextCheckingRequest::trace(visitor);
}
-// static
-PassRefPtrWillBeRawPtr<SpellCheckRequest> SpellCheckRequest::create(TextCheckingTypeMask textCheckingOptions, TextCheckingProcessType processType, PassRefPtrWillBeRawPtr<Range> checkingRange, PassRefPtrWillBeRawPtr<Range> paragraphRange, int requestNumber)
+void SpellCheckRequest::dispose()
{
- ASSERT(checkingRange);
- ASSERT(paragraphRange);
+ if (m_checkingRange)
+ m_checkingRange->dispose();
+ if (m_paragraphRange && m_paragraphRange != m_checkingRange)
+ m_paragraphRange->dispose();
+}
- String text = checkingRange->text();
- if (!text.length())
+// static
+PassRefPtrWillBeRawPtr<SpellCheckRequest> SpellCheckRequest::create(TextCheckingTypeMask textCheckingOptions, TextCheckingProcessType processType, const EphemeralRange& checkingRange, const EphemeralRange& paragraphRange, int requestNumber)
+{
+ String text = plainText(checkingRange, TextIteratorEmitsObjectReplacementCharacter);
+ if (text.isEmpty())
return nullptr;
- const DocumentMarkerVector& markers = checkingRange->ownerDocument().markers().markersInRange(EphemeralRange(checkingRange.get()), DocumentMarker::SpellCheckClientMarkers());
+ RefPtrWillBeRawPtr<Range> checkingRangeObject = createRange(checkingRange);
+ RefPtrWillBeRawPtr<Range> paragraphRangeObject = nullptr;
+ // Share identical Range objects.
+ if (checkingRange == paragraphRange)
+ paragraphRangeObject = checkingRangeObject;
+ else
+ paragraphRangeObject = createRange(paragraphRange);
+
+ const DocumentMarkerVector& markers = checkingRangeObject->ownerDocument().markers().markersInRange(checkingRange, DocumentMarker::SpellCheckClientMarkers());
Vector<uint32_t> hashes(markers.size());
Vector<unsigned> offsets(markers.size());
- for (size_t i = 0; i < markers.size(); i++) {
+ for (size_t i = 0; i < markers.size(); ++i) {
hashes[i] = markers[i]->hash();
offsets[i] = markers[i]->startOffset();
}
- return adoptRefWillBeNoop(new SpellCheckRequest(checkingRange, paragraphRange, text, textCheckingOptions, processType, hashes, offsets, requestNumber));
+ return adoptRefWillBeNoop(new SpellCheckRequest(checkingRangeObject, paragraphRangeObject, text, textCheckingOptions, processType, hashes, offsets, requestNumber));
}
const TextCheckingRequestData& SpellCheckRequest::data() const
@@ -213,12 +226,10 @@ void SpellCheckRequester::invokeRequest(PassRefPtrWillBeRawPtr<SpellCheckRequest
void SpellCheckRequester::clearProcessingRequest()
{
- // This assumes that m_processingRequest's Ranges aren't shared.
- if (m_processingRequest->checkingRange())
- m_processingRequest->checkingRange()->dispose();
- if (m_processingRequest->paragraphRange())
- m_processingRequest->paragraphRange()->dispose();
+ if (!m_processingRequest)
+ return;
+ m_processingRequest->dispose();
m_processingRequest.clear();
}

Powered by Google App Engine
This is Rietveld 408576698