Skip to content
Permalink
Browse files
AtomicMarkupTokenBase must die
https://bugs.webkit.org/show_bug.cgi?id=107513

Reviewed by Eric Seidel.

Now that NEW_XML has been removed from the tree, there is no reason to
have AtomicMarkupTokenBase exist as a templated base class for
AtomicHTMLToken. This patch just merges the code back into
AtomicHTMLToken.

* html/parser/HTMLToken.h:
(AtomicHTMLToken):
(WebCore::AtomicHTMLToken::type):
(WebCore::AtomicHTMLToken::name):
(WebCore::AtomicHTMLToken::setName):
(WebCore::AtomicHTMLToken::selfClosing):
(WebCore::AtomicHTMLToken::getAttributeItem):
(WebCore::AtomicHTMLToken::attributes):
(WebCore::AtomicHTMLToken::characters):
(WebCore::AtomicHTMLToken::charactersLength):
(WebCore::AtomicHTMLToken::isAll8BitData):
(WebCore::AtomicHTMLToken::comment):
(WebCore::AtomicHTMLToken::publicIdentifier):
(WebCore::AtomicHTMLToken::systemIdentifier):
(WebCore::AtomicHTMLToken::clearExternalCharacters):
(WebCore::AtomicHTMLToken::AtomicHTMLToken):
(WebCore::AtomicMarkupTokenBase::initializeAttributes):
(WebCore):
* xml/parser/MarkupTokenBase.h:


Canonical link: https://commits.webkit.org/125752@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@140403 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Adam Barth committed Jan 22, 2013
1 parent 5c9c935 commit 3740f6a313b7eae35145f611fd33800494bb655c
Showing with 250 additions and 240 deletions.
  1. +32 −0 Source/WebCore/ChangeLog
  2. +196 −4 Source/WebCore/html/parser/HTMLToken.h
  3. +3 −6 Source/WebCore/html/parser/HTMLTokenizer.cpp
  4. +19 −230 Source/WebCore/xml/parser/MarkupTokenBase.h
@@ -1,3 +1,35 @@
2013-01-22 Adam Barth <abarth@webkit.org>

AtomicMarkupTokenBase must die
https://bugs.webkit.org/show_bug.cgi?id=107513

Reviewed by Eric Seidel.

Now that NEW_XML has been removed from the tree, there is no reason to
have AtomicMarkupTokenBase exist as a templated base class for
AtomicHTMLToken. This patch just merges the code back into
AtomicHTMLToken.

* html/parser/HTMLToken.h:
(AtomicHTMLToken):
(WebCore::AtomicHTMLToken::type):
(WebCore::AtomicHTMLToken::name):
(WebCore::AtomicHTMLToken::setName):
(WebCore::AtomicHTMLToken::selfClosing):
(WebCore::AtomicHTMLToken::getAttributeItem):
(WebCore::AtomicHTMLToken::attributes):
(WebCore::AtomicHTMLToken::characters):
(WebCore::AtomicHTMLToken::charactersLength):
(WebCore::AtomicHTMLToken::isAll8BitData):
(WebCore::AtomicHTMLToken::comment):
(WebCore::AtomicHTMLToken::publicIdentifier):
(WebCore::AtomicHTMLToken::systemIdentifier):
(WebCore::AtomicHTMLToken::clearExternalCharacters):
(WebCore::AtomicHTMLToken::AtomicHTMLToken):
(WebCore::AtomicMarkupTokenBase::initializeAttributes):
(WebCore):
* xml/parser/MarkupTokenBase.h:

2013-01-22 Eric Seidel <eric@webkit.org>

Turn on ENABLE_THREADED_HTML_PARSER for Chromium (it's still disabled at runtime)
@@ -61,7 +61,7 @@ class HTMLToken : public MarkupTokenBase<HTMLTokenTypes, HTMLTokenTypes::Doctype
}
};

class AtomicHTMLToken : public AtomicMarkupTokenBase<HTMLToken>, public RefCounted<AtomicHTMLToken> {
class AtomicHTMLToken : public RefCounted<AtomicHTMLToken> {
WTF_MAKE_NONCOPYABLE(AtomicHTMLToken);
public:
static PassRefPtr<AtomicHTMLToken> create(HTMLToken& token)
@@ -88,16 +88,130 @@ class AtomicHTMLToken : public AtomicMarkupTokenBase<HTMLToken>, public RefCount
ASSERT(m_type == HTMLTokenTypes::DOCTYPE);
return m_doctypeData->m_forceQuirks;
}

HTMLTokenTypes::Type type() const { return m_type; }

const AtomicString& name() const
{
ASSERT(usesName());
return m_name;
}

void setName(const AtomicString& name)
{
ASSERT(usesName());
m_name = name;
}

bool selfClosing() const
{
ASSERT(m_type == HTMLTokenTypes::StartTag || m_type == HTMLTokenTypes::EndTag);
return m_selfClosing;
}

Attribute* getAttributeItem(const QualifiedName& attributeName)
{
ASSERT(usesAttributes());
return findAttributeInVector(m_attributes, attributeName);
}

Vector<Attribute>& attributes()
{
ASSERT(usesAttributes());
return m_attributes;
}

const Vector<Attribute>& attributes() const
{
ASSERT(usesAttributes());
return m_attributes;
}

const UChar* characters() const
{
ASSERT(m_type == HTMLTokenTypes::Character);
return m_externalCharacters;
}

size_t charactersLength() const
{
ASSERT(m_type == HTMLTokenTypes::Character);
return m_externalCharactersLength;
}

bool isAll8BitData() const
{
return m_isAll8BitData;
}

const String& comment() const
{
ASSERT(m_type == HTMLTokenTypes::Comment);
return m_data;
}

// FIXME: Distinguish between a missing public identifer and an empty one.
WTF::Vector<UChar>& publicIdentifier() const
{
ASSERT(m_type == HTMLTokenTypes::DOCTYPE);
return m_doctypeData->m_publicIdentifier;
}

// FIXME: Distinguish between a missing system identifer and an empty one.
WTF::Vector<UChar>& systemIdentifier() const
{
ASSERT(m_type == HTMLTokenTypes::DOCTYPE);
return m_doctypeData->m_systemIdentifier;
}

void clearExternalCharacters()
{
m_externalCharacters = 0;
m_externalCharactersLength = 0;
m_isAll8BitData = false;
}

private:
explicit AtomicHTMLToken(HTMLToken& token)
: AtomicMarkupTokenBase<HTMLToken>(&token)
: m_type(token.type())
{
switch (m_type) {
case HTMLTokenTypes::Uninitialized:
ASSERT_NOT_REACHED();
break;
case HTMLTokenTypes::DOCTYPE:
m_name = AtomicString(token.nameString());
m_doctypeData = token.releaseDoctypeData();
break;
case HTMLTokenTypes::EndOfFile:
break;
case HTMLTokenTypes::StartTag:
case HTMLTokenTypes::EndTag: {
m_selfClosing = token.selfClosing();
m_name = AtomicString(token.nameString());
initializeAttributes(token.attributes());
break;
}
case HTMLTokenTypes::Comment:
if (token.isAll8BitData())
m_data = String::make8BitFrom16BitSource(token.comment().data(), token.comment().size());
else
m_data = String(token.comment().data(), token.comment().size());
break;
case HTMLTokenTypes::Character:
m_externalCharacters = token.characters().data();
m_externalCharactersLength = token.characters().size();
m_isAll8BitData = token.isAll8BitData();
break;
default:
break;
}
}

#if ENABLE(THREADED_HTML_PARSER)

explicit AtomicHTMLToken(const CompactHTMLToken& token)
: AtomicMarkupTokenBase<HTMLToken>(token.type())
: m_type(token.type())
{
switch (m_type) {
case HTMLTokenTypes::Uninitialized:
@@ -136,12 +250,90 @@ class AtomicHTMLToken : public AtomicMarkupTokenBase<HTMLToken>, public RefCount

#endif

explicit AtomicHTMLToken(HTMLTokenTypes::Type type)
: m_type(type)
, m_externalCharacters(0)
, m_externalCharactersLength(0)
, m_isAll8BitData(false)
, m_selfClosing(false)
{
}

AtomicHTMLToken(HTMLTokenTypes::Type type, const AtomicString& name, const Vector<Attribute>& attributes = Vector<Attribute>())
: AtomicMarkupTokenBase<HTMLToken>(type, name, attributes)
: m_type(type)
, m_name(name)
, m_externalCharacters(0)
, m_externalCharactersLength(0)
, m_isAll8BitData(false)
, m_selfClosing(false)
, m_attributes(attributes)
{
ASSERT(usesName());
}

HTMLTokenTypes::Type m_type;

void initializeAttributes(const HTMLToken::AttributeList& attributes);
QualifiedName nameForAttribute(const HTMLToken::Attribute&) const;

bool usesName() const;

bool usesAttributes() const;

// "name" for DOCTYPE, StartTag, and EndTag
AtomicString m_name;

// "data" for Comment
String m_data;

// "characters" for Character
//
// We don't want to copy the the characters out of the Token, so we
// keep a pointer to its buffer instead. This buffer is owned by the
// Token and causes a lifetime dependence between these objects.
//
// FIXME: Add a mechanism for "internalizing" the characters when the
// HTMLToken is destructed.
const UChar* m_externalCharacters;
size_t m_externalCharactersLength;
bool m_isAll8BitData;

// For DOCTYPE
OwnPtr<HTMLTokenTypes::DoctypeData> m_doctypeData;

// For StartTag and EndTag
bool m_selfClosing;

Vector<Attribute> m_attributes;
};

inline void AtomicHTMLToken::initializeAttributes(const HTMLToken::AttributeList& attributes)
{
size_t size = attributes.size();
if (!size)
return;

m_attributes.clear();
m_attributes.reserveInitialCapacity(size);
for (size_t i = 0; i < size; ++i) {
const HTMLToken::Attribute& attribute = attributes[i];
if (attribute.m_name.isEmpty())
continue;

// FIXME: We should be able to add the following ASSERT once we fix
// https://bugs.webkit.org/show_bug.cgi?id=62971
// ASSERT(attribute.m_nameRange.m_start);
ASSERT(attribute.m_nameRange.m_end);
ASSERT(attribute.m_valueRange.m_start);
ASSERT(attribute.m_valueRange.m_end);

AtomicString value(attribute.m_value.data(), attribute.m_value.size());
const QualifiedName& name = nameForAttribute(attribute);
if (!findAttributeInVector(m_attributes, name))
m_attributes.append(Attribute(name, value));
}
}

}

#endif
@@ -49,20 +49,17 @@ using namespace HTMLNames;

// This has to go in a .cpp file, as the linker doesn't like it being included more than once.
// We don't have an HTMLToken.cpp though, so this is the next best place.
template<>
QualifiedName AtomicMarkupTokenBase<HTMLToken>::nameForAttribute(const AttributeBase& attribute) const
QualifiedName AtomicHTMLToken::nameForAttribute(const AttributeBase& attribute) const
{
return QualifiedName(nullAtom, AtomicString(attribute.m_name.data(), attribute.m_name.size()), nullAtom);
}

template<>
bool AtomicMarkupTokenBase<HTMLToken>::usesName() const
bool AtomicHTMLToken::usesName() const
{
return m_type == HTMLTokenTypes::StartTag || m_type == HTMLTokenTypes::EndTag || m_type == HTMLTokenTypes::DOCTYPE;
}

template<>
bool AtomicMarkupTokenBase<HTMLToken>::usesAttributes() const
bool AtomicHTMLToken::usesAttributes() const
{
return m_type == HTMLTokenTypes::StartTag || m_type == HTMLTokenTypes::EndTag;
}

0 comments on commit 3740f6a

Please sign in to comment.