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

Side by Side Diff: third_party/WebKit/Source/core/editing/markers/SpellCheckMarkerListImpl.cpp

Issue 2899413003: [DMC #13] Don't create RenderedDocumentMarkers in SpellCheckMarkerListImpl (Closed)
Patch Set: Remove dep Created 3 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/editing/markers/SpellCheckMarkerListImpl.h" 5 #include "core/editing/markers/SpellCheckMarkerListImpl.h"
6 6
7 #include "core/editing/markers/DocumentMarkerListEditor.h" 7 #include "core/editing/markers/DocumentMarkerListEditor.h"
8 #include "core/editing/markers/RenderedDocumentMarker.h"
9 8
10 namespace blink { 9 namespace blink {
11 10
12 bool SpellCheckMarkerListImpl::IsEmpty() const { 11 bool SpellCheckMarkerListImpl::IsEmpty() const {
13 return markers_.IsEmpty(); 12 return markers_.IsEmpty();
14 } 13 }
15 14
16 void SpellCheckMarkerListImpl::Add(DocumentMarker* marker) { 15 void SpellCheckMarkerListImpl::Add(DocumentMarker* marker) {
17 RenderedDocumentMarker* rendered_marker =
18 RenderedDocumentMarker::Create(*marker);
19 if (markers_.IsEmpty() || 16 if (markers_.IsEmpty() ||
20 markers_.back()->EndOffset() < marker->StartOffset()) { 17 markers_.back()->EndOffset() < marker->StartOffset()) {
21 markers_.push_back(rendered_marker); 18 markers_.push_back(marker);
22 return; 19 return;
23 } 20 }
24 21
25 auto first_overlapping = std::lower_bound( 22 auto first_overlapping = std::lower_bound(
26 markers_.begin(), markers_.end(), rendered_marker, 23 markers_.begin(), markers_.end(), marker,
27 [](const Member<DocumentMarker>& marker_in_list, 24 [](const Member<DocumentMarker>& marker_in_list,
28 const DocumentMarker* marker_to_insert) { 25 const DocumentMarker* marker_to_insert) {
29 return marker_in_list->EndOffset() < marker_to_insert->StartOffset(); 26 return marker_in_list->EndOffset() < marker_to_insert->StartOffset();
30 }); 27 });
31 28
32 size_t index = first_overlapping - markers_.begin(); 29 size_t index = first_overlapping - markers_.begin();
33 markers_.insert(index, rendered_marker); 30 markers_.insert(index, marker);
34 const auto inserted = markers_.begin() + index; 31 const auto inserted = markers_.begin() + index;
35 first_overlapping = inserted + 1; 32 first_overlapping = inserted + 1;
36 // TODO(rlanday): optimize this loop so it runs in O(N) time and not O(N^2) 33 // TODO(rlanday): optimize this loop so it runs in O(N) time and not O(N^2)
37 for (const auto i = first_overlapping; 34 for (const auto i = first_overlapping;
38 i != markers_.end() && 35 i != markers_.end() &&
39 (*i)->StartOffset() <= (*inserted)->EndOffset();) { 36 (*i)->StartOffset() <= (*inserted)->EndOffset();) {
40 (*inserted)->SetStartOffset( 37 (*inserted)->SetStartOffset(
41 std::min((*inserted)->StartOffset(), (*i)->StartOffset())); 38 std::min((*inserted)->StartOffset(), (*i)->StartOffset()));
42 (*inserted)->SetEndOffset( 39 (*inserted)->SetEndOffset(
43 std::max((*inserted)->EndOffset(), (*i)->EndOffset())); 40 std::max((*inserted)->EndOffset(), (*i)->EndOffset()));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 const String& marker_text = node_text.Substring(start, length); 85 const String& marker_text = node_text.Substring(start, length);
89 if (words.Contains(marker_text)) { 86 if (words.Contains(marker_text)) {
90 markers_.erase(j - 1); 87 markers_.erase(j - 1);
91 removed_markers = true; 88 removed_markers = true;
92 } 89 }
93 } 90 }
94 return removed_markers; 91 return removed_markers;
95 } 92 }
96 93
97 } // namespace blink 94 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698