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

Unified Diff: third_party/WebKit/Source/core/editing/iterators/ProgressiveTextAccumulator.cpp

Issue 1604783002: ALL-IN-ONE: Optimization to previousBoundary() and nextBoundary() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@progressive_accumulator
Patch Set: Created 4 years, 11 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
Index: third_party/WebKit/Source/core/editing/iterators/ProgressiveTextAccumulator.cpp
diff --git a/third_party/WebKit/Source/core/editing/iterators/ProgressiveTextAccumulator.cpp b/third_party/WebKit/Source/core/editing/iterators/ProgressiveTextAccumulator.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..6c4c7e4f505134afb14e495f398ef2017a408524
--- /dev/null
+++ b/third_party/WebKit/Source/core/editing/iterators/ProgressiveTextAccumulator.cpp
@@ -0,0 +1,57 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/editing/iterators/ProgressiveTextAccumulator.h"
+
+namespace blink {
+
+template<typename Iterator>
+ProgressiveTextAccumulator<Iterator>::ProgressiveTextAccumulator(const PositionType& start, const PositionType& end, TextIteratorBehaviorFlags behavior)
+ : m_iterator(start, end, behavior)
+ , m_maxAccumulate(1024)
+ , m_accumulatedInCurrentNode(0)
+{
+}
+
+template<typename Iterator>
+void ProgressiveTextAccumulator<Iterator>::advance()
+{
+ ASSERT(!m_iterator.atEnd());
+ ASSERT(m_accumulatedInCurrentNode <= m_iterator.length());
+
+ if (m_accumulatedInCurrentNode == m_iterator.length()) {
+ m_accumulatedInCurrentNode = 0;
+ m_iterator.advance();
+ }
+}
+
+template<typename Iterator>
+int ProgressiveTextAccumulator<Iterator>::expandToValidLength(int accumulateLength)
+{
+ int ans = accumulateLength;
+ // Make sure we copy whole code points (on well-formed UTF-16).
+ if (m_accumulatedInCurrentNode + accumulateLength < m_iterator.length()) {
+ UChar last = m_iterator.characterAt(m_accumulatedInCurrentNode + accumulateLength - 1);
+ UChar next = m_iterator.characterAt(m_accumulatedInCurrentNode + accumulateLength);
+ if (arePairingSurrogates(last, next))
+ ans = accumulateLength + 1;
+ }
+ // TODO(xiaochengh): Do we have to copy whole grapheme clusters?
+ return ans;
+}
+
+template<typename Iterator>
+bool ProgressiveTextAccumulator<Iterator>::arePairingSurrogates(UChar first, UChar second)
+{
+ if (Iterator::direction == TextIteratorDirection::TextIteratorForward)
+ return U16_IS_LEAD(first) && U16_IS_TRAIL(second);
+ return U16_IS_TRAIL(first) && U16_IS_LEAD(second);
+}
+
+template class CORE_TEMPLATE_EXPORT ProgressiveTextAccumulator<TextIteratorAlgorithm<EditingStrategy>>;
+template class CORE_TEMPLATE_EXPORT ProgressiveTextAccumulator<TextIteratorAlgorithm<EditingInComposedTreeStrategy>>;
+template class CORE_TEMPLATE_EXPORT ProgressiveTextAccumulator<SimplifiedBackwardsTextIteratorAlgorithm<EditingStrategy>>;
+template class CORE_TEMPLATE_EXPORT ProgressiveTextAccumulator<SimplifiedBackwardsTextIteratorAlgorithm<EditingInComposedTreeStrategy>>;
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698