summaryrefslogtreecommitdiff
path: root/Source/WebCore/dom/ElementData.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/dom/ElementData.cpp')
-rw-r--r--Source/WebCore/dom/ElementData.cpp73
1 files changed, 31 insertions, 42 deletions
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<UniqueElementData*>(this);
+ if (is<UniqueElementData>(*this))
+ delete downcast<UniqueElementData>(this);
else
- delete static_cast<ShareableElementData*>(this);
+ delete downcast<ShareableElementData>(this);
}
ElementData::ElementData()
@@ -61,13 +63,13 @@ static size_t sizeForShareableElementDataWithAttributeCount(unsigned count)
return sizeof(ShareableElementData) + sizeof(Attribute) * count;
}
-PassRef<ShareableElementData> ShareableElementData::createWithAttributes(const Vector<Attribute>& attributes)
+Ref<ShareableElementData> ShareableElementData::createWithAttributes(const Vector<Attribute>& attributes)
{
void* slot = WTF::fastMalloc(sizeForShareableElementDataWithAttributeCount(attributes.size()));
return adoptRef(*new (NotNull, slot) ShareableElementData(attributes));
}
-PassRef<UniqueElementData> UniqueElementData::create()
+Ref<UniqueElementData> 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<UniqueElementData> ElementData::makeUniqueCopy() const
+Ref<UniqueElementData> ElementData::makeUniqueCopy() const
{
if (isUnique())
return adoptRef(*new UniqueElementData(static_cast<const UniqueElementData&>(*this)));
return adoptRef(*new UniqueElementData(static_cast<const ShareableElementData&>(*this)));
}
-PassRef<ShareableElementData> UniqueElementData::makeShareableCopy() const
+Ref<ShareableElementData> 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;
}
}