Simple line layout(regression): Calling innerText on RenderFlow with multiple childre...
[WebKit-https.git] / Source / WebCore / editing / TextIterator.cpp
index b6ac079..b15d5ad 100644 (file)
@@ -548,20 +548,18 @@ bool TextIterator::handleTextNode()
             return true;
         // Use the simple layout runs to iterate over the text content.
         ASSERT(renderer.parent() && is<RenderBlockFlow>(renderer.parent()));
-        const auto& blockFlow = downcast<RenderBlockFlow>(*renderer.parent());
-        SimpleLineLayout::RunResolver runResolver(blockFlow, *layout);
-        auto range = runResolver.rangeForRenderer(renderer);
         unsigned endPosition = (m_node == m_endContainer) ? static_cast<unsigned>(m_endOffset) : rendererText.length();
-        // Simple line layout run positions are all absolute to the parent flow.
-        // Offsetting is required when multiple renderers are present.
-        if (previousTextNode && previousTextNode != &textNode) {
-            const RenderObject& previousRenderer = *previousTextNode->renderer();
-            if (previousRenderer.parent() != &blockFlow)
-                m_previousTextLengthInFlow = 0;
-            else
-                m_previousTextLengthInFlow += previousTextNode->renderer()->text()->length();
+        const auto& blockFlow = downcast<RenderBlockFlow>(*renderer.parent());
+        if (!m_flowRunResolverCache || &m_flowRunResolverCache->flow() != &blockFlow) {
+            m_flowRunResolverCache = std::make_unique<SimpleLineLayout::RunResolver>(blockFlow, *layout);
+            m_previousTextLengthInFlow = 0;
+        } else if (previousTextNode && previousTextNode != &textNode) {
+            // Simple line layout run positions are all absolute to the parent flow.
+            // Offsetting is required when multiple renderers are present.
+            m_previousTextLengthInFlow += previousTextNode->renderer()->text()->length();
         }
         // Skip to m_offset position.
+        auto range = m_flowRunResolverCache->rangeForRenderer(renderer);
         auto it = range.begin();
         auto end = range.end();
         while (it != end && (*it).end() <= (static_cast<unsigned>(m_offset) + m_previousTextLengthInFlow))