Title: [158214] trunk/Source/WebCore
Revision
158214
Author
[email protected]
Date
2013-10-29 13:25:44 -0700 (Tue, 29 Oct 2013)

Log Message

Make SimpleLineLayout::Layout a variable size object
https://bugs.webkit.org/show_bug.cgi?id=123459

Reviewed by Andreas Kling.

Less memory, less indirection.

* rendering/SimpleLineLayout.cpp:
(WebCore::SimpleLineLayout::canUseFor):
(WebCore::SimpleLineLayout::create):
(WebCore::SimpleLineLayout::Layout::create):
(WebCore::SimpleLineLayout::Layout::Layout):
* rendering/SimpleLineLayout.h:
* rendering/SimpleLineLayoutFunctions.cpp:
(WebCore::SimpleLineLayout::hitTestFlow):
* rendering/SimpleLineLayoutFunctions.h:
(WebCore::SimpleLineLayout::computeFlowFirstLineBaseline):
(WebCore::SimpleLineLayout::computeFlowLastLineBaseline):
(WebCore::SimpleLineLayout::findTextCaretMinimumOffset):
(WebCore::SimpleLineLayout::findTextCaretMaximumOffset):
(WebCore::SimpleLineLayout::containsTextCaretOffset):
(WebCore::SimpleLineLayout::isTextRendered):
* rendering/SimpleLineLayoutResolver.h:
(WebCore::SimpleLineLayout::RunResolver::end):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (158213 => 158214)


--- trunk/Source/WebCore/ChangeLog	2013-10-29 20:02:06 UTC (rev 158213)
+++ trunk/Source/WebCore/ChangeLog	2013-10-29 20:25:44 UTC (rev 158214)
@@ -1,3 +1,30 @@
+2013-10-29  Antti Koivisto  <[email protected]>
+
+        Make SimpleLineLayout::Layout a variable size object
+        https://bugs.webkit.org/show_bug.cgi?id=123459
+
+        Reviewed by Andreas Kling.
+
+        Less memory, less indirection.
+
+        * rendering/SimpleLineLayout.cpp:
+        (WebCore::SimpleLineLayout::canUseFor):
+        (WebCore::SimpleLineLayout::create):
+        (WebCore::SimpleLineLayout::Layout::create):
+        (WebCore::SimpleLineLayout::Layout::Layout):
+        * rendering/SimpleLineLayout.h:
+        * rendering/SimpleLineLayoutFunctions.cpp:
+        (WebCore::SimpleLineLayout::hitTestFlow):
+        * rendering/SimpleLineLayoutFunctions.h:
+        (WebCore::SimpleLineLayout::computeFlowFirstLineBaseline):
+        (WebCore::SimpleLineLayout::computeFlowLastLineBaseline):
+        (WebCore::SimpleLineLayout::findTextCaretMinimumOffset):
+        (WebCore::SimpleLineLayout::findTextCaretMaximumOffset):
+        (WebCore::SimpleLineLayout::containsTextCaretOffset):
+        (WebCore::SimpleLineLayout::isTextRendered):
+        * rendering/SimpleLineLayoutResolver.h:
+        (WebCore::SimpleLineLayout::RunResolver::end):
+
 2013-10-29  Andreas Kling  <[email protected]>
 
         RenderObject::outlineStyleForRepaint() should return a reference.

Modified: trunk/Source/WebCore/rendering/SimpleLineLayout.cpp (158213 => 158214)


--- trunk/Source/WebCore/rendering/SimpleLineLayout.cpp	2013-10-29 20:02:06 UTC (rev 158213)
+++ trunk/Source/WebCore/rendering/SimpleLineLayout.cpp	2013-10-29 20:25:44 UTC (rev 158214)
@@ -236,8 +236,6 @@
 
 std::unique_ptr<Layout> create(RenderBlockFlow& flow)
 {
-    auto layout = std::make_unique<Layout>();
-
     RenderText& textRenderer = toRenderText(*flow.firstChild());
     ASSERT(!textRenderer.firstTextBox());
 
@@ -250,6 +248,9 @@
     LazyLineBreakIterator lineBreakIterator(textRenderer.text(), style.locale());
     int nextBreakable = -1;
 
+    Layout::RunVector runs;
+    unsigned lineCount = 0;
+
     unsigned lineEndOffset = 0;
     while (lineEndOffset < textLength) {
         lineEndOffset = skipWhitespaces(textRenderer, lineEndOffset, textLength);
@@ -318,17 +319,29 @@
         adjustRunOffsets(lineRuns, textAlign, lineWidth.committedWidth(), lineWidth.availableWidth());
 
         for (unsigned i = 0; i < lineRuns.size(); ++i)
-            layout->runs.append(lineRuns[i]);
+            runs.append(lineRuns[i]);
 
-        layout->runs.last().isEndOfLine = true;
-        layout->lineCount++;
+        runs.last().isEndOfLine = true;
+        ++lineCount;
     }
 
     textRenderer.clearNeedsLayout();
 
-    layout->runs.shrinkToFit();
-    return layout;
+    return Layout::create(runs, lineCount);
 }
 
+std::unique_ptr<Layout> Layout::create(const RunVector& runVector, unsigned lineCount)
+{
+    void* slot = WTF::fastMalloc(sizeof(Layout) + sizeof(Run) * runVector.size());
+    return std::unique_ptr<Layout>(new (NotNull, slot) Layout(runVector, lineCount));
 }
+
+Layout::Layout(const RunVector& runVector, unsigned lineCount)
+    : runCount(runVector.size())
+    , lineCount(lineCount)
+{
+    memcpy(runs, runVector.data(), runCount * sizeof(Run));
 }
+
+}
+}

Modified: trunk/Source/WebCore/rendering/SimpleLineLayout.h (158213 => 158214)


--- trunk/Source/WebCore/rendering/SimpleLineLayout.h	2013-10-29 20:02:06 UTC (rev 158213)
+++ trunk/Source/WebCore/rendering/SimpleLineLayout.h	2013-10-29 20:25:44 UTC (rev 158214)
@@ -29,6 +29,11 @@
 #include <wtf/Vector.h>
 #include <wtf/text/WTFString.h>
 
+#if COMPILER(MSVC)
+#pragma warning(push)
+#pragma warning(disable: 4200) // Disable "zero-sized array in struct/union" warning
+#endif
+
 namespace WebCore {
 
 class RenderBlockFlow;
@@ -54,10 +59,15 @@
 };
 
 struct Layout {
-    Layout() : lineCount(0) { }
+    typedef Vector<Run, 10> RunVector;
+    static std::unique_ptr<Layout> create(const RunVector&, unsigned lineCount);
 
+    unsigned runCount;
     unsigned lineCount;
-    Vector<Run> runs;
+    Run runs[0];
+
+private:
+    Layout(const RunVector&, unsigned lineCount);
 };
 
 std::unique_ptr<Layout> create(RenderBlockFlow&);
@@ -65,4 +75,8 @@
 }
 }
 
+#if COMPILER(MSVC)
+#pragma warning(pop)
 #endif
+
+#endif

Modified: trunk/Source/WebCore/rendering/SimpleLineLayoutFunctions.cpp (158213 => 158214)


--- trunk/Source/WebCore/rendering/SimpleLineLayoutFunctions.cpp	2013-10-29 20:02:06 UTC (rev 158213)
+++ trunk/Source/WebCore/rendering/SimpleLineLayoutFunctions.cpp	2013-10-29 20:25:44 UTC (rev 158214)
@@ -74,7 +74,7 @@
     if (hitTestAction != HitTestForeground)
         return false;
 
-    if (layout.runs.isEmpty())
+    if (!layout.runCount)
         return false;
 
     RenderStyle& style = flow.style();

Modified: trunk/Source/WebCore/rendering/SimpleLineLayoutFunctions.h (158213 => 158214)


--- trunk/Source/WebCore/rendering/SimpleLineLayoutFunctions.h	2013-10-29 20:02:06 UTC (rev 158213)
+++ trunk/Source/WebCore/rendering/SimpleLineLayoutFunctions.h	2013-10-29 20:25:44 UTC (rev 158214)
@@ -70,34 +70,34 @@
 
 inline LayoutUnit computeFlowFirstLineBaseline(const RenderBlockFlow& flow, const Layout& layout)
 {
-    ASSERT_UNUSED(layout, !layout.runs.isEmpty());
+    ASSERT_UNUSED(layout, layout.runCount);
     return flow.borderAndPaddingBefore() + baselineFromFlow(flow);
 }
 
 inline LayoutUnit computeFlowLastLineBaseline(const RenderBlockFlow& flow, const Layout& layout)
 {
-    ASSERT(!layout.runs.isEmpty());
-    return flow.borderAndPaddingBefore() + lineHeightFromFlow(flow) * (layout.runs.size() - 1) + baselineFromFlow(flow);
+    ASSERT(layout.runCount);
+    return flow.borderAndPaddingBefore() + lineHeightFromFlow(flow) * (layout.runCount - 1) + baselineFromFlow(flow);
 }
 
 inline unsigned findTextCaretMinimumOffset(const RenderText&, const Layout& layout)
 {
-    if (layout.runs.isEmpty())
+    if (!layout.runCount)
         return 0;
     return layout.runs[0].textOffset;
 }
 
 inline unsigned findTextCaretMaximumOffset(const RenderText& renderer, const Layout& layout)
 {
-    if (layout.runs.isEmpty())
+    if (!layout.runCount)
         return renderer.textLength();
-    auto& last = layout.runs[layout.runs.size() - 1];
+    auto& last = layout.runs[layout.runCount - 1];
     return last.textOffset + last.textLength;
 }
 
 inline bool containsTextCaretOffset(const RenderText&, const Layout& layout, unsigned offset)
 {
-    for (unsigned i = 0; i < layout.runs.size(); ++i) {
+    for (unsigned i = 0; i < layout.runCount; ++i) {
         auto& line = layout.runs[i];
         if (offset < line.textOffset)
             return false;
@@ -109,7 +109,7 @@
 
 inline bool isTextRendered(const RenderText&, const Layout& layout)
 {
-    for (unsigned i = 0; i < layout.runs.size(); ++i) {
+    for (unsigned i = 0; i < layout.runCount; ++i) {
         if (layout.runs[i].textLength)
             return true;
     }

Modified: trunk/Source/WebCore/rendering/SimpleLineLayoutResolver.h (158213 => 158214)


--- trunk/Source/WebCore/rendering/SimpleLineLayoutResolver.h	2013-10-29 20:02:06 UTC (rev 158213)
+++ trunk/Source/WebCore/rendering/SimpleLineLayoutResolver.h	2013-10-29 20:25:44 UTC (rev 158214)
@@ -210,7 +210,7 @@
 
 inline RunResolver::Iterator RunResolver::end() const
 {
-    return Iterator(*this, m_layout.runs.size());
+    return Iterator(*this, m_layout.runCount);
 }
 
 inline LineResolver::Iterator::Iterator(RunResolver::Iterator runIterator)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to