Commit afe9c578 authored by antti@apple.com's avatar antti@apple.com
Browse files

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):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@158214 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 8994ea64
2013-10-29 Antti Koivisto <antti@apple.com>
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 <akling@apple.com>
RenderObject::outlineStyleForRepaint() should return a reference.
......
......@@ -236,8 +236,6 @@ static void adjustRunOffsets(Vector<Run, 4>& lineRuns, ETextAlign textAlign, flo
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 @@ std::unique_ptr<Layout> create(RenderBlockFlow& flow)
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,16 +319,28 @@ std::unique_ptr<Layout> create(RenderBlockFlow& flow)
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));
}
}
......
......@@ -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 Run {
};
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 @@ std::unique_ptr<Layout> create(RenderBlockFlow&);
}
}
#if COMPILER(MSVC)
#pragma warning(pop)
#endif
#endif
......@@ -74,7 +74,7 @@ bool hitTestFlow(const RenderBlockFlow& flow, const Layout& layout, const HitTes
if (hitTestAction != HitTestForeground)
return false;
if (layout.runs.isEmpty())
if (!layout.runCount)
return false;
RenderStyle& style = flow.style();
......
......@@ -70,34 +70,34 @@ inline LayoutUnit computeFlowHeight(const RenderBlockFlow& flow, const Layout& l
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 containsTextCaretOffset(const RenderText&, const Layout& layout, uns
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;
}
......
......@@ -210,7 +210,7 @@ inline RunResolver::Iterator RunResolver::begin() const
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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment