Changeset 158214 in webkit


Ignore:
Timestamp:
Oct 29, 2013 1:25:44 PM (10 years ago)
Author:
Antti Koivisto
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):

Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r158212 r158214  
     12013-10-29  Antti Koivisto  <antti@apple.com>
     2
     3        Make SimpleLineLayout::Layout a variable size object
     4        https://bugs.webkit.org/show_bug.cgi?id=123459
     5
     6        Reviewed by Andreas Kling.
     7
     8        Less memory, less indirection.
     9
     10        * rendering/SimpleLineLayout.cpp:
     11        (WebCore::SimpleLineLayout::canUseFor):
     12        (WebCore::SimpleLineLayout::create):
     13        (WebCore::SimpleLineLayout::Layout::create):
     14        (WebCore::SimpleLineLayout::Layout::Layout):
     15        * rendering/SimpleLineLayout.h:
     16        * rendering/SimpleLineLayoutFunctions.cpp:
     17        (WebCore::SimpleLineLayout::hitTestFlow):
     18        * rendering/SimpleLineLayoutFunctions.h:
     19        (WebCore::SimpleLineLayout::computeFlowFirstLineBaseline):
     20        (WebCore::SimpleLineLayout::computeFlowLastLineBaseline):
     21        (WebCore::SimpleLineLayout::findTextCaretMinimumOffset):
     22        (WebCore::SimpleLineLayout::findTextCaretMaximumOffset):
     23        (WebCore::SimpleLineLayout::containsTextCaretOffset):
     24        (WebCore::SimpleLineLayout::isTextRendered):
     25        * rendering/SimpleLineLayoutResolver.h:
     26        (WebCore::SimpleLineLayout::RunResolver::end):
     27
    1282013-10-29  Andreas Kling  <akling@apple.com>
    229
  • trunk/Source/WebCore/rendering/SimpleLineLayout.cpp

    r158196 r158214  
    237237std::unique_ptr<Layout> create(RenderBlockFlow& flow)
    238238{
    239     auto layout = std::make_unique<Layout>();
    240 
    241239    RenderText& textRenderer = toRenderText(*flow.firstChild());
    242240    ASSERT(!textRenderer.firstTextBox());
     
    250248    LazyLineBreakIterator lineBreakIterator(textRenderer.text(), style.locale());
    251249    int nextBreakable = -1;
     250
     251    Layout::RunVector runs;
     252    unsigned lineCount = 0;
    252253
    253254    unsigned lineEndOffset = 0;
     
    319320
    320321        for (unsigned i = 0; i < lineRuns.size(); ++i)
    321             layout->runs.append(lineRuns[i]);
    322 
    323         layout->runs.last().isEndOfLine = true;
    324         layout->lineCount++;
     322            runs.append(lineRuns[i]);
     323
     324        runs.last().isEndOfLine = true;
     325        ++lineCount;
    325326    }
    326327
    327328    textRenderer.clearNeedsLayout();
    328329
    329     layout->runs.shrinkToFit();
    330     return layout;
    331 }
    332 
    333 }
    334 }
     330    return Layout::create(runs, lineCount);
     331}
     332
     333std::unique_ptr<Layout> Layout::create(const RunVector& runVector, unsigned lineCount)
     334{
     335    void* slot = WTF::fastMalloc(sizeof(Layout) + sizeof(Run) * runVector.size());
     336    return std::unique_ptr<Layout>(new (NotNull, slot) Layout(runVector, lineCount));
     337}
     338
     339Layout::Layout(const RunVector& runVector, unsigned lineCount)
     340    : runCount(runVector.size())
     341    , lineCount(lineCount)
     342{
     343    memcpy(runs, runVector.data(), runCount * sizeof(Run));
     344}
     345
     346}
     347}
  • trunk/Source/WebCore/rendering/SimpleLineLayout.h

    r158196 r158214  
    3030#include <wtf/text/WTFString.h>
    3131
     32#if COMPILER(MSVC)
     33#pragma warning(push)
     34#pragma warning(disable: 4200) // Disable "zero-sized array in struct/union" warning
     35#endif
     36
    3237namespace WebCore {
    3338
     
    5560
    5661struct Layout {
    57     Layout() : lineCount(0) { }
     62    typedef Vector<Run, 10> RunVector;
     63    static std::unique_ptr<Layout> create(const RunVector&, unsigned lineCount);
    5864
     65    unsigned runCount;
    5966    unsigned lineCount;
    60     Vector<Run> runs;
     67    Run runs[0];
     68
     69private:
     70    Layout(const RunVector&, unsigned lineCount);
    6171};
    6272
     
    6676}
    6777
     78#if COMPILER(MSVC)
     79#pragma warning(pop)
    6880#endif
     81
     82#endif
  • trunk/Source/WebCore/rendering/SimpleLineLayoutFunctions.cpp

    r158196 r158214  
    7575        return false;
    7676
    77     if (layout.runs.isEmpty())
     77    if (!layout.runCount)
    7878        return false;
    7979
  • trunk/Source/WebCore/rendering/SimpleLineLayoutFunctions.h

    r158107 r158214  
    7171inline LayoutUnit computeFlowFirstLineBaseline(const RenderBlockFlow& flow, const Layout& layout)
    7272{
    73     ASSERT_UNUSED(layout, !layout.runs.isEmpty());
     73    ASSERT_UNUSED(layout, layout.runCount);
    7474    return flow.borderAndPaddingBefore() + baselineFromFlow(flow);
    7575}
     
    7777inline LayoutUnit computeFlowLastLineBaseline(const RenderBlockFlow& flow, const Layout& layout)
    7878{
    79     ASSERT(!layout.runs.isEmpty());
    80     return flow.borderAndPaddingBefore() + lineHeightFromFlow(flow) * (layout.runs.size() - 1) + baselineFromFlow(flow);
     79    ASSERT(layout.runCount);
     80    return flow.borderAndPaddingBefore() + lineHeightFromFlow(flow) * (layout.runCount - 1) + baselineFromFlow(flow);
    8181}
    8282
    8383inline unsigned findTextCaretMinimumOffset(const RenderText&, const Layout& layout)
    8484{
    85     if (layout.runs.isEmpty())
     85    if (!layout.runCount)
    8686        return 0;
    8787    return layout.runs[0].textOffset;
     
    9090inline unsigned findTextCaretMaximumOffset(const RenderText& renderer, const Layout& layout)
    9191{
    92     if (layout.runs.isEmpty())
     92    if (!layout.runCount)
    9393        return renderer.textLength();
    94     auto& last = layout.runs[layout.runs.size() - 1];
     94    auto& last = layout.runs[layout.runCount - 1];
    9595    return last.textOffset + last.textLength;
    9696}
     
    9898inline bool containsTextCaretOffset(const RenderText&, const Layout& layout, unsigned offset)
    9999{
    100     for (unsigned i = 0; i < layout.runs.size(); ++i) {
     100    for (unsigned i = 0; i < layout.runCount; ++i) {
    101101        auto& line = layout.runs[i];
    102102        if (offset < line.textOffset)
     
    110110inline bool isTextRendered(const RenderText&, const Layout& layout)
    111111{
    112     for (unsigned i = 0; i < layout.runs.size(); ++i) {
     112    for (unsigned i = 0; i < layout.runCount; ++i) {
    113113        if (layout.runs[i].textLength)
    114114            return true;
  • trunk/Source/WebCore/rendering/SimpleLineLayoutResolver.h

    r158196 r158214  
    211211inline RunResolver::Iterator RunResolver::end() const
    212212{
    213     return Iterator(*this, m_layout.runs.size());
     213    return Iterator(*this, m_layout.runCount);
    214214}
    215215
Note: See TracChangeset for help on using the changeset viewer.