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

Side by Side 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: push Range de-dup into SpellCheckRequester::create() Created 5 years, 2 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 DEFINE_TRACE(SpellCheckRequest) 61 DEFINE_TRACE(SpellCheckRequest)
62 { 62 {
63 visitor->trace(m_requester); 63 visitor->trace(m_requester);
64 visitor->trace(m_checkingRange); 64 visitor->trace(m_checkingRange);
65 visitor->trace(m_paragraphRange); 65 visitor->trace(m_paragraphRange);
66 visitor->trace(m_rootEditableElement); 66 visitor->trace(m_rootEditableElement);
67 TextCheckingRequest::trace(visitor); 67 TextCheckingRequest::trace(visitor);
68 } 68 }
69 69
70 // static 70 // static
71 PassRefPtrWillBeRawPtr<SpellCheckRequest> SpellCheckRequest::create(TextChecking TypeMask textCheckingOptions, TextCheckingProcessType processType, PassRefPtrWil lBeRawPtr<Range> checkingRange, PassRefPtrWillBeRawPtr<Range> paragraphRange, in t requestNumber) 71 PassRefPtrWillBeRawPtr<SpellCheckRequest> SpellCheckRequest::create(TextChecking TypeMask textCheckingOptions, TextCheckingProcessType processType, const Ephemer alRange& checkingRange, const EphemeralRange& paragraphRange, int requestNumber)
72 { 72 {
73 ASSERT(checkingRange); 73 String text = plainText(checkingRange, TextIteratorEmitsObjectReplacementCha racter);
74 ASSERT(paragraphRange); 74 if (text.isEmpty())
75
76 String text = checkingRange->text();
77 if (!text.length())
78 return nullptr; 75 return nullptr;
79 76
80 const DocumentMarkerVector& markers = checkingRange->ownerDocument().markers ().markersInRange(EphemeralRange(checkingRange.get()), DocumentMarker::SpellChec kClientMarkers()); 77 RefPtrWillBeRawPtr<Range> checkingRangeObject = createRange(checkingRange);
78 RefPtrWillBeRawPtr<Range> paragraphRangeObject = nullptr;
79 // Share identical Range objects.
80 if (checkingRange == paragraphRange)
81 paragraphRangeObject = checkingRangeObject;
82 else
83 paragraphRangeObject = createRange(paragraphRange);
84
85 const DocumentMarkerVector& markers = checkingRangeObject->ownerDocument().m arkers().markersInRange(checkingRange, DocumentMarker::SpellCheckClientMarkers() );
81 Vector<uint32_t> hashes(markers.size()); 86 Vector<uint32_t> hashes(markers.size());
82 Vector<unsigned> offsets(markers.size()); 87 Vector<unsigned> offsets(markers.size());
83 for (size_t i = 0; i < markers.size(); i++) { 88 for (size_t i = 0; i < markers.size(); ++i) {
84 hashes[i] = markers[i]->hash(); 89 hashes[i] = markers[i]->hash();
85 offsets[i] = markers[i]->startOffset(); 90 offsets[i] = markers[i]->startOffset();
86 } 91 }
87 92
88 return adoptRefWillBeNoop(new SpellCheckRequest(checkingRange, paragraphRang e, text, textCheckingOptions, processType, hashes, offsets, requestNumber)); 93 return adoptRefWillBeNoop(new SpellCheckRequest(checkingRangeObject, paragra phRangeObject, text, textCheckingOptions, processType, hashes, offsets, requestN umber));
89 } 94 }
90 95
91 const TextCheckingRequestData& SpellCheckRequest::data() const 96 const TextCheckingRequestData& SpellCheckRequest::data() const
92 { 97 {
93 return m_requestData; 98 return m_requestData;
94 } 99 }
95 100
96 void SpellCheckRequest::didSucceed(const Vector<TextCheckingResult>& results) 101 void SpellCheckRequest::didSucceed(const Vector<TextCheckingResult>& results)
97 { 102 {
98 if (!m_requester) 103 if (!m_requester)
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 void SpellCheckRequester::invokeRequest(PassRefPtrWillBeRawPtr<SpellCheckRequest > request) 212 void SpellCheckRequester::invokeRequest(PassRefPtrWillBeRawPtr<SpellCheckRequest > request)
208 { 213 {
209 ASSERT(!m_processingRequest); 214 ASSERT(!m_processingRequest);
210 m_processingRequest = request; 215 m_processingRequest = request;
211 client().requestCheckingOfString(m_processingRequest); 216 client().requestCheckingOfString(m_processingRequest);
212 } 217 }
213 218
214 void SpellCheckRequester::clearProcessingRequest() 219 void SpellCheckRequester::clearProcessingRequest()
215 { 220 {
216 // This assumes that m_processingRequest's Ranges aren't shared. 221 // This assumes that m_processingRequest's Ranges aren't shared.
217 if (m_processingRequest->checkingRange()) 222 RefPtrWillBeRawPtr<Range> checkingRange = m_processingRequest->checkingRange ();
yosin_UTC9 2015/09/26 15:46:06 nit: Can we have |SpellCheckRequest::dispose()| or
sof 2015/09/26 16:18:29 Addressed.
218 m_processingRequest->checkingRange()->dispose(); 223 RefPtrWillBeRawPtr<Range> paragraphRange = m_processingRequest->paragraphRan ge();
219 if (m_processingRequest->paragraphRange()) 224 if (checkingRange)
220 m_processingRequest->paragraphRange()->dispose(); 225 checkingRange->dispose();
226 if (paragraphRange && paragraphRange != checkingRange)
227 paragraphRange->dispose();
221 228
222 m_processingRequest.clear(); 229 m_processingRequest.clear();
223 } 230 }
224 231
225 void SpellCheckRequester::enqueueRequest(PassRefPtrWillBeRawPtr<SpellCheckReques t> request) 232 void SpellCheckRequester::enqueueRequest(PassRefPtrWillBeRawPtr<SpellCheckReques t> request)
226 { 233 {
227 ASSERT(request); 234 ASSERT(request);
228 bool continuation = false; 235 bool continuation = false;
229 if (!m_requestQueue.isEmpty()) { 236 if (!m_requestQueue.isEmpty()) {
230 RefPtrWillBeRawPtr<SpellCheckRequest> lastRequest = m_requestQueue.last( ); 237 RefPtrWillBeRawPtr<SpellCheckRequest> lastRequest = m_requestQueue.last( );
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 } 296 }
290 297
291 DEFINE_TRACE(SpellCheckRequester) 298 DEFINE_TRACE(SpellCheckRequester)
292 { 299 {
293 visitor->trace(m_frame); 300 visitor->trace(m_frame);
294 visitor->trace(m_processingRequest); 301 visitor->trace(m_processingRequest);
295 visitor->trace(m_requestQueue); 302 visitor->trace(m_requestQueue);
296 } 303 }
297 304
298 } // namespace blink 305 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698