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

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

Issue 2922623002: Make DocumentMarkerListEditor::RemoveMarkers() more efficient (Closed)
Patch Set: 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 | third_party/WebKit/Source/core/editing/markers/DocumentMarkerListEditorTest.cpp » ('j') | 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/DocumentMarkerListEditor.h" 5 #include "core/editing/markers/DocumentMarkerListEditor.h"
6 6
7 #include "core/editing/markers/SpellCheckMarkerListImpl.h" 7 #include "core/editing/markers/SpellCheckMarkerListImpl.h"
8 8
9 namespace blink { 9 namespace blink {
10 10
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 dst_list->Add(&marker); 45 dst_list->Add(&marker);
46 didMoveMarker = true; 46 didMoveMarker = true;
47 } 47 }
48 48
49 // Remove the range of markers that were moved to dstNode 49 // Remove the range of markers that were moved to dstNode
50 src_list->erase(0, it - src_list->begin()); 50 src_list->erase(0, it - src_list->begin());
51 51
52 return didMoveMarker; 52 return didMoveMarker;
53 } 53 }
54 54
55 // TODO(rlanday): this method was created by cutting and pasting code from
56 // DocumentMarkerController::RemoveMarkers(), it should be refactored in a
57 // future CL
58 bool DocumentMarkerListEditor::RemoveMarkers(MarkerList* list, 55 bool DocumentMarkerListEditor::RemoveMarkers(MarkerList* list,
59 unsigned start_offset, 56 unsigned start_offset,
60 int length) { 57 int length) {
61 bool doc_dirty = false;
62 const unsigned end_offset = start_offset + length; 58 const unsigned end_offset = start_offset + length;
59
yosin_UTC9 2017/06/02 01:11:45 nit: Please remove an extra blank line.
63 MarkerList::iterator start_pos = std::upper_bound( 60 MarkerList::iterator start_pos = std::upper_bound(
64 list->begin(), list->end(), start_offset, 61 list->begin(), list->end(), start_offset,
65 [](size_t start_offset, const Member<DocumentMarker>& marker) { 62 [](size_t start_offset, const Member<DocumentMarker>& marker) {
66 return start_offset < marker->EndOffset(); 63 return start_offset < marker->EndOffset();
67 }); 64 });
68 for (MarkerList::iterator i = start_pos; i != list->end();) {
69 const DocumentMarker& marker = *i->Get();
70 65
71 // markers are returned in order, so stop if we are now past the specified 66 MarkerList::iterator end_pos = std::lower_bound(
72 // range 67 list->begin(), list->end(), end_offset,
73 if (marker.StartOffset() >= end_offset) 68 [](const Member<DocumentMarker>& marker, size_t end_offset) {
74 break; 69 return marker->StartOffset() < end_offset;
70 });
75 71
76 list->erase(i - list->begin()); 72 list->erase(start_pos - list->begin(), end_pos - start_pos);
77 doc_dirty = true; 73 return start_pos != end_pos;
78 }
79
80 return doc_dirty;
81 } 74 }
82 75
83 // TODO(rlanday): make this not take O(n^2) time when all the markers are 76 // TODO(rlanday): make this not take O(n^2) time when all the markers are
84 // removed 77 // removed
85 bool DocumentMarkerListEditor::ShiftMarkersContentDependent( 78 bool DocumentMarkerListEditor::ShiftMarkersContentDependent(
86 MarkerList* list, 79 MarkerList* list,
87 unsigned offset, 80 unsigned offset,
88 unsigned old_length, 81 unsigned old_length,
89 unsigned new_length) { 82 unsigned new_length) {
90 bool did_shift_marker = false; 83 bool did_shift_marker = false;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 did_shift_marker = true; 128 did_shift_marker = true;
136 marker.SetStartOffset(result.value().start_offset); 129 marker.SetStartOffset(result.value().start_offset);
137 marker.SetEndOffset(result.value().end_offset); 130 marker.SetEndOffset(result.value().end_offset);
138 } 131 }
139 } 132 }
140 133
141 return did_shift_marker; 134 return did_shift_marker;
142 } 135 }
143 136
144 } // namespace blink 137 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/editing/markers/DocumentMarkerListEditorTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698