Remove Element::textFromChildren().

Instead just use textContent() and teach HTMLStyleElement how to atomize
its children. I also added the optimization to Node::textContent so that
Text just returns its value instead of allocating a new buffer which
avoids malloc and copy when getting the textContent of text.

R=abarth@chromium.org

Review URL: https://codereview.chromium.org/864613002
This commit is contained in:
Elliott Sprehn 2015-01-20 14:26:54 -08:00
parent b3e4c186ee
commit 0fcd743a64
4 changed files with 6 additions and 44 deletions

View File

@ -1305,46 +1305,6 @@ void Element::dispatchFocusOutEvent(const AtomicString& eventType, Element* newF
dispatchScopedEventDispatchMediator(FocusOutEventDispatchMediator::create(FocusEvent::create(eventType, true, false, document().domWindow(), 0, newFocusedElement)));
}
String Element::textFromChildren()
{
Text* firstTextNode = 0;
bool foundMultipleTextNodes = false;
unsigned totalLength = 0;
for (Node* child = firstChild(); child; child = child->nextSibling()) {
if (!child->isTextNode())
continue;
Text* text = toText(child);
if (!firstTextNode)
firstTextNode = text;
else
foundMultipleTextNodes = true;
unsigned length = text->data().length();
if (length > std::numeric_limits<unsigned>::max() - totalLength)
return emptyString();
totalLength += length;
}
if (!firstTextNode)
return emptyString();
if (firstTextNode && !foundMultipleTextNodes) {
firstTextNode->atomize();
return firstTextNode->data();
}
StringBuilder content;
content.reserveCapacity(totalLength);
for (Node* child = firstTextNode; child; child = child->nextSibling()) {
if (!child->isTextNode())
continue;
content.append(toText(child)->data());
}
ASSERT(content.length() == totalLength);
return content.toString();
}
// FIXME(sky): Remove pseudoElementSpecifier.
RenderStyle* Element::computedStyle(PseudoId pseudoElementSpecifier)
{

View File

@ -295,8 +295,6 @@ public:
void click();
String textFromChildren();
protected:
Element(const QualifiedName& tagName, Document*, ConstructionType);

View File

@ -908,6 +908,8 @@ ContainerNode* Node::ownerScope() const
String Node::textContent() const
{
if (isTextNode())
return toText(this)->data();
StringBuilder content;
for (const Node* node = this; node; node = NodeTraversal::next(*node, this)) {
if (node->isTextNode())

View File

@ -30,6 +30,7 @@
#include "sky/engine/core/dom/Document.h"
#include "sky/engine/core/dom/Element.h"
#include "sky/engine/core/dom/StyleEngine.h"
#include "sky/engine/core/dom/Text.h"
#include "sky/engine/core/dom/shadow/ShadowRoot.h"
#include "sky/engine/core/frame/LocalFrame.h"
#include "sky/engine/platform/TraceEvent.h"
@ -124,8 +125,9 @@ void HTMLStyleElement::process()
MediaQueryEvaluator screenEval("screen", true);
if (screenEval.eval(mediaQueries.get())) {
const String& text = textFromChildren();
m_sheet = document().styleEngine()->createSheet(this, text);
if (hasOneTextChild())
toText(firstChild())->atomize();
m_sheet = document().styleEngine()->createSheet(this, textContent());
m_sheet->setMediaQueries(mediaQueries.release());
}