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

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

Issue 2949333002: Optimize DocumentMarkerController::MarkerAtPosition() (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/editing/markers/DocumentMarkerController.cpp
diff --git a/third_party/WebKit/Source/core/editing/markers/DocumentMarkerController.cpp b/third_party/WebKit/Source/core/editing/markers/DocumentMarkerController.cpp
index a9309fae840172d93c5b50057c0fa4918ed1b977..7b357808a2677bfb48a2d14efa920a0d499b80e9 100644
--- a/third_party/WebKit/Source/core/editing/markers/DocumentMarkerController.cpp
+++ b/third_party/WebKit/Source/core/editing/markers/DocumentMarkerController.cpp
@@ -367,16 +367,35 @@ DocumentMarker* DocumentMarkerController::MarkerAtPosition(
DocumentMarker::MarkerTypes marker_types) {
if (!PossiblyHasMarkers(marker_types))
return nullptr;
+
Node* const node = position.ComputeContainerNode();
+ MarkerLists* const markers = markers_.at(node);
+ if (!markers)
+ return nullptr;
+
const unsigned offset =
static_cast<unsigned>(position.ComputeOffsetInContainerNode());
- const auto& markers = MarkersFor(node, marker_types);
- const auto& it =
- std::find_if(markers.begin(), markers.end(), [=](DocumentMarker* marker) {
- return marker->StartOffset() < offset && offset < marker->EndOffset();
- });
- return it == markers.end() ? nullptr : *it;
+ // This position can't be in the interior of a marker if it occurs at an
+ // endpoint of the node
+ if (offset == 0 ||
+ offset == static_cast<unsigned>(node->MaxCharacterOffset()))
+ return nullptr;
+
+ // Query each of the DocumentMarkerLists until we find a marker at the
+ // specified position (or have gone through all the MarkerTypes)
+ for (DocumentMarker::MarkerType type : marker_types) {
+ const DocumentMarkerList* const list = ListForType(markers, type);
+ if (!list)
+ continue;
+
+ const HeapVector<Member<DocumentMarker>>& results =
+ list->MarkersIntersectingRange(offset, offset);
+ if (!results.IsEmpty())
+ return results.front();
+ }
+
+ return nullptr;
}
DocumentMarkerVector DocumentMarkerController::MarkersFor(
« 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