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

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

Issue 2723663002: Refactor DocumentMarkerController (Closed)
Patch Set: Rebase on https://codereview.chromium.org/2755013004 Created 3 years, 9 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "core/editing/markers/SpellingMarkerList.h"
6
7 #include <utility>
8 #include "core/dom/Text.h"
9
10 namespace blink {
11
12 SpellingMarkerList::SpellingMarkerList(
13 DocumentMarkerController* documentMarkerController)
14 : EditingMarkerListThatMergesTouchingMarkers(documentMarkerController) {}
15
16 DocumentMarker::MarkerType SpellingMarkerList::allowedMarkerType() const {
17 return DocumentMarker::Spelling;
18 }
19
20 void SpellingMarkerList::removeMarkersForWords(const Text& textNode,
21 const Vector<String>& words) {
22 // Build a second vector and swap with m_markers to avoid O(n^2) performance
Xiaocheng 2017/03/17 23:56:34 This is still quadratic running time: O(m_markers.
rlanday 2017/03/18 01:12:27 It's linear in m_markers.size() and words.size(),
Xiaocheng 2017/03/18 01:58:09 Using anything more complicated than a simple nest
23 HeapVector<Member<DocumentMarker>> newMarkerList;
24
25 for (Member<DocumentMarker> marker : m_markers) {
26 unsigned start = marker->startOffset();
27 unsigned length = marker->endOffset() - marker->startOffset();
28
29 String markerText = textNode.data().substring(start, length);
30 if (!words.contains(markerText))
31 newMarkerList.push_back(marker);
32 }
33
34 std::swap(m_markers, newMarkerList);
35 }
36
37 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698