Commit de41eb43 authored by Adithya Srinivasan's avatar Adithya Srinivasan Committed by Commit Bot

Remove StringImpl allocation in AtomicHTMLToken::InitializeAttributes

Uses the AtomicString(Vector<UChar>) constructor for Attribute values.
This is to remove an unnecessary memory allocation and conversion of
attribute values to String (using Value8BitIfNecessary). The allocation
is unnecessary for cases where the value is already present in
AtomicStringTable.

This CL also changes lookupHTMLTag to directly return an AtomicString,
instead of converting it to a StringImpl and then back to an
AtomicString.

Bug: 
Change-Id: I756f99cd57ebc20828d4a0430ba34f1018c730a4
Reviewed-on: https://chromium-review.googlesource.com/685512Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Commit-Queue: Adithya Srinivasan <adithyas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#505029}
parent 3cf20755
......@@ -13,12 +13,12 @@ namespace blink {
using namespace {{namespace}}Names;
StringImpl* lookup{{namespace}}Tag(const UChar* data, unsigned length) {
const AtomicString& lookup{{namespace}}Tag(const UChar* data, unsigned length) {
DCHECK(data);
DCHECK(length);
{% macro trie_return_statement(tag) %}{{tag}}Tag.LocalName().Impl(){% endmacro %}
{% macro trie_return_statement(tag) %}{{tag}}Tag.LocalName(){% endmacro %}
{{ trie_length_switch(length_tries, trie_return_statement, false) | indent(4) }}
return nullptr;
return g_null_atom;
}
} // namespace blink
......@@ -7,11 +7,11 @@
#define {{namespace}}ElementLookupTrie_h
#include "core/CoreExport.h"
#include "platform/wtf/text/StringImpl.h"
#include "platform/wtf/text/AtomicString.h"
namespace blink {
CORE_EXPORT StringImpl* lookup{{namespace}}Tag(const UChar* data, unsigned length);
CORE_EXPORT const AtomicString& lookup{{namespace}}Tag(const UChar* data, unsigned length);
} // namespace blink
......
......@@ -114,9 +114,9 @@ class CORE_EXPORT AtomicHTMLToken {
case HTMLToken::kStartTag:
case HTMLToken::kEndTag: {
self_closing_ = token.SelfClosing();
if (StringImpl* tag_name =
if (const AtomicString& tag_name =
lookupHTMLTag(token.GetName().data(), token.GetName().size()))
name_ = AtomicString(tag_name);
name_ = tag_name;
else
name_ = AtomicString(token.GetName());
InitializeAttributes(token.Attributes());
......@@ -229,7 +229,13 @@ inline void AtomicHTMLToken::InitializeAttributes(
attribute.NameRange().CheckValid();
attribute.ValueRange().CheckValid();
AtomicString value(attribute.Value8BitIfNecessary());
AtomicString value(attribute.ValueAsVector());
// attribute.ValueAsVector.data() is null for attributes with no values, but
// the null atom is used to represent absence of attributes; attributes with
// no values have the value set to an empty atom instead.
if (value == g_null_atom) {
value = g_empty_atom;
}
const QualifiedName& name = NameForAttribute(attribute);
// FIXME: This is N^2 for the number of attributes.
if (!FindAttributeInVector(attributes_, name))
......
......@@ -115,6 +115,7 @@ class HTMLToken {
return AttemptStaticStringCreation(name_, kLikely8Bit);
}
const Vector<UChar, 32>& NameAsVector() const { return name_; }
const Vector<UChar, 32>& ValueAsVector() const { return value_; }
void AppendToName(UChar c) { name_.push_back(c); }
......
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