From 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Tue, 27 Jun 2017 06:07:23 +0000 Subject: webkitgtk-2.16.5 --- Source/WebCore/dom/ElementData.cpp | 73 ++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 42 deletions(-) (limited to 'Source/WebCore/dom/ElementData.cpp') diff --git a/Source/WebCore/dom/ElementData.cpp b/Source/WebCore/dom/ElementData.cpp index 86f852d05..4b9ebf889 100644 --- a/Source/WebCore/dom/ElementData.cpp +++ b/Source/WebCore/dom/ElementData.cpp @@ -27,16 +27,18 @@ #include "ElementData.h" #include "Attr.h" +#include "HTMLNames.h" #include "StyleProperties.h" +#include "XMLNames.h" namespace WebCore { void ElementData::destroy() { - if (isUnique()) - delete static_cast(this); + if (is(*this)) + delete downcast(this); else - delete static_cast(this); + delete downcast(this); } ElementData::ElementData() @@ -61,13 +63,13 @@ static size_t sizeForShareableElementDataWithAttributeCount(unsigned count) return sizeof(ShareableElementData) + sizeof(Attribute) * count; } -PassRef ShareableElementData::createWithAttributes(const Vector& attributes) +Ref ShareableElementData::createWithAttributes(const Vector& attributes) { void* slot = WTF::fastMalloc(sizeForShareableElementDataWithAttributeCount(attributes.size())); return adoptRef(*new (NotNull, slot) ShareableElementData(attributes)); } -PassRef UniqueElementData::create() +Ref UniqueElementData::create() { return adoptRef(*new UniqueElementData); } @@ -140,19 +142,20 @@ UniqueElementData::UniqueElementData(const ShareableElementData& other) ASSERT(!other.m_inlineStyle || !other.m_inlineStyle->isMutable()); m_inlineStyle = other.m_inlineStyle; - m_attributeVector.reserveCapacity(other.length()); - for (unsigned i = 0; i < other.length(); ++i) + unsigned otherLength = other.length(); + m_attributeVector.reserveCapacity(otherLength); + for (unsigned i = 0; i < otherLength; ++i) m_attributeVector.uncheckedAppend(other.m_attributeArray[i]); } -PassRef ElementData::makeUniqueCopy() const +Ref ElementData::makeUniqueCopy() const { if (isUnique()) return adoptRef(*new UniqueElementData(static_cast(*this))); return adoptRef(*new UniqueElementData(static_cast(*this))); } -PassRef UniqueElementData::makeShareableCopy() const +Ref UniqueElementData::makeShareableCopy() const { void* slot = WTF::fastMalloc(sizeForShareableElementDataWithAttributeCount(m_attributeVector.size())); return adoptRef(*new (NotNull, slot) ShareableElementData(*this)); @@ -175,46 +178,32 @@ bool ElementData::isEquivalent(const ElementData* other) const return true; } -unsigned ElementData::findAttributeIndexByNameSlowCase(const AtomicString& name, bool shouldIgnoreAttributeCase) const +Attribute* UniqueElementData::findAttributeByName(const QualifiedName& name) { - // Continue to checking case-insensitively and/or full namespaced names if necessary: - const Attribute* attributes = attributeBase(); - unsigned length = this->length(); - for (unsigned i = 0; i < length; ++i) { - const Attribute& attribute = attributes[i]; - if (!attribute.name().hasPrefix()) { - if (shouldIgnoreAttributeCase && equalIgnoringCase(name, attribute.localName())) - return i; - } else { - // FIXME: Would be faster to do this comparison without calling toString, which - // generates a temporary string by concatenation. But this branch is only reached - // if the attribute name has a prefix, which is rare in HTML. - if (equalPossiblyIgnoringCase(name, attribute.name().toString(), shouldIgnoreAttributeCase)) - return i; - } + for (auto& attribute : m_attributeVector) { + if (attribute.name().matches(name)) + return &attribute; } - return attributeNotFound; + return nullptr; } -unsigned ElementData::findAttributeIndexByNameForAttributeNode(const Attr* attr, bool shouldIgnoreAttributeCase) const +const Attribute* ElementData::findLanguageAttribute() const { - ASSERT(attr); - const Attribute* attributes = attributeBase(); - unsigned count = length(); - for (unsigned i = 0; i < count; ++i) { - if (attributes[i].name().matchesIgnoringCaseForLocalName(attr->qualifiedName(), shouldIgnoreAttributeCase)) - return i; - } - return attributeNotFound; -} + ASSERT(XMLNames::langAttr.localName() == HTMLNames::langAttr.localName()); -Attribute* UniqueElementData::findAttributeByName(const QualifiedName& name) -{ - for (unsigned i = 0, count = m_attributeVector.size(); i < count; ++i) { - if (m_attributeVector.at(i).name().matches(name)) - return &m_attributeVector.at(i); + const Attribute* attributes = attributeBase(); + // Spec: xml:lang takes precedence over html:lang -- http://www.w3.org/TR/xhtml1/#C_7 + const Attribute* languageAttribute = nullptr; + for (unsigned i = 0, count = length(); i < count; ++i) { + const QualifiedName& name = attributes[i].name(); + if (name.localName() != HTMLNames::langAttr.localName()) + continue; + if (name.namespaceURI() == XMLNames::langAttr.namespaceURI()) + return &attributes[i]; + if (name.namespaceURI() == HTMLNames::langAttr.namespaceURI()) + languageAttribute = &attributes[i]; } - return nullptr; + return languageAttribute; } } -- cgit v1.2.1