diff options
Diffstat (limited to 'WebCore/dom/NamedAttrMap.cpp')
-rw-r--r-- | WebCore/dom/NamedAttrMap.cpp | 55 |
1 files changed, 15 insertions, 40 deletions
diff --git a/WebCore/dom/NamedAttrMap.cpp b/WebCore/dom/NamedAttrMap.cpp index 56b40b9..d8a6ba8 100644 --- a/WebCore/dom/NamedAttrMap.cpp +++ b/WebCore/dom/NamedAttrMap.cpp @@ -130,7 +130,7 @@ PassRefPtr<Node> NamedNodeMap::setNamedItem(Node* arg, ExceptionCode& ec) return 0; } - if (a->name() == idAttr) + if (attr->isId()) m_element->updateId(old ? old->value() : nullAtom, a->value()); // ### slightly inefficient - resizes attribute array twice. @@ -155,9 +155,9 @@ PassRefPtr<Node> NamedNodeMap::removeNamedItem(const QualifiedName& name, Except return 0; } - RefPtr<Node> r = a->createAttrIfNeeded(m_element); + RefPtr<Attr> r = a->createAttrIfNeeded(m_element); - if (name == idAttr) + if (r->isId()) m_element->updateId(a->value(), nullAtom); removeAttribute(name); @@ -172,52 +172,27 @@ PassRefPtr<Node> NamedNodeMap::item(unsigned index) const return m_attributes[index]->createAttrIfNeeded(m_element); } -// We use a boolean parameter instead of calling shouldIgnoreAttributeCase so that the caller -// can tune the behaviour (hasAttribute is case sensitive whereas getAttribute is not). -Attribute* NamedNodeMap::getAttributeItem(const String& name, bool shouldIgnoreAttributeCase) const +Attribute* NamedNodeMap::getAttributeItemSlowCase(const String& name, bool shouldIgnoreAttributeCase) const { unsigned len = length(); - bool doSlowCheck = shouldIgnoreAttributeCase; - - // Optimize for the case where the attribute exists and its name exactly matches. + + // Continue to checking case-insensitively and/or full namespaced names if necessary: for (unsigned i = 0; i < len; ++i) { const QualifiedName& attrName = m_attributes[i]->name(); if (!attrName.hasPrefix()) { - if (name == attrName.localName()) + if (shouldIgnoreAttributeCase && equalIgnoringCase(name, attrName.localName())) + return m_attributes[i].get(); + } 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, attrName.toString(), shouldIgnoreAttributeCase)) return m_attributes[i].get(); - } else - doSlowCheck = true; - } - - // Continue to checking case-insensitively and/or full namespaced names if necessary: - if (doSlowCheck) { - for (unsigned i = 0; i < len; ++i) { - const QualifiedName& attrName = m_attributes[i]->name(); - if (!attrName.hasPrefix()) { - if (shouldIgnoreAttributeCase && equalIgnoringCase(name, attrName.localName())) - return m_attributes[i].get(); - } 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, attrName.toString(), shouldIgnoreAttributeCase)) - return m_attributes[i].get(); - } } } return 0; } -Attribute* NamedNodeMap::getAttributeItem(const QualifiedName& name) const -{ - unsigned len = length(); - for (unsigned i = 0; i < len; ++i) { - if (m_attributes[i]->name().matches(name)) - return m_attributes[i].get(); - } - return 0; -} - void NamedNodeMap::clearAttributes() { detachAttributesFromElement(); @@ -242,8 +217,8 @@ void NamedNodeMap::setAttributes(const NamedNodeMap& other) // If assigning the map changes the id attribute, we need to call // updateId. - Attribute *oldId = getAttributeItem(idAttr); - Attribute *newId = other.getAttributeItem(idAttr); + Attribute* oldId = getAttributeItem(m_element->idAttributeName()); + Attribute* newId = other.getAttributeItem(m_element->idAttributeName()); if (oldId || newId) m_element->updateId(oldId ? oldId->value() : nullAtom, newId ? newId->value() : nullAtom); |