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

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

Issue 2922623002: Make DocumentMarkerListEditor::RemoveMarkers() more efficient (Closed)
Patch Set: Remove blank line Created 3 years, 7 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/editing/markers/DocumentMarkerListEditorTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/editing/markers/DocumentMarkerListEditor.cpp
diff --git a/third_party/WebKit/Source/core/editing/markers/DocumentMarkerListEditor.cpp b/third_party/WebKit/Source/core/editing/markers/DocumentMarkerListEditor.cpp
index b629b20b3212183d45bdf9cba90c1df3961766e7..f7477a830e2b6833b6e1bf447a0dae49c2ea66ec 100644
--- a/third_party/WebKit/Source/core/editing/markers/DocumentMarkerListEditor.cpp
+++ b/third_party/WebKit/Source/core/editing/markers/DocumentMarkerListEditor.cpp
@@ -52,32 +52,24 @@ bool DocumentMarkerListEditor::MoveMarkers(MarkerList* src_list,
return didMoveMarker;
}
-// TODO(rlanday): this method was created by cutting and pasting code from
-// DocumentMarkerController::RemoveMarkers(), it should be refactored in a
-// future CL
bool DocumentMarkerListEditor::RemoveMarkers(MarkerList* list,
unsigned start_offset,
int length) {
- bool doc_dirty = false;
const unsigned end_offset = start_offset + length;
MarkerList::iterator start_pos = std::upper_bound(
list->begin(), list->end(), start_offset,
[](size_t start_offset, const Member<DocumentMarker>& marker) {
return start_offset < marker->EndOffset();
});
- for (MarkerList::iterator i = start_pos; i != list->end();) {
- const DocumentMarker& marker = *i->Get();
- // markers are returned in order, so stop if we are now past the specified
- // range
- if (marker.StartOffset() >= end_offset)
- break;
-
- list->erase(i - list->begin());
- doc_dirty = true;
- }
+ MarkerList::iterator end_pos = std::lower_bound(
+ list->begin(), list->end(), end_offset,
+ [](const Member<DocumentMarker>& marker, size_t end_offset) {
+ return marker->StartOffset() < end_offset;
+ });
- return doc_dirty;
+ list->erase(start_pos - list->begin(), end_pos - start_pos);
+ return start_pos != end_pos;
}
// TODO(rlanday): make this not take O(n^2) time when all the markers are
« 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