Diff
Modified: trunk/Source/WebCore/ChangeLog (107476 => 107477)
--- trunk/Source/WebCore/ChangeLog 2012-02-11 08:56:19 UTC (rev 107476)
+++ trunk/Source/WebCore/ChangeLog 2012-02-11 14:50:28 UTC (rev 107477)
@@ -1,3 +1,64 @@
+2012-02-11 Andreas Kling <awesomekl...@apple.com>
+
+ Use Element's hasName/hasID flags to avoid unnecessary work when looking up name/id attributes.
+ <http://webkit.org/b/77845>
+
+ Reviewed by Anders Carlsson.
+
+ Have Element::getIdAttribute() check the hasID() flag before looking up the attribute.
+ Add an Element::getNameAttribute() to do the same thing with hasName().
+ Update call sites to make use of these helpers whenever possible.
+
+ * accessibility/AccessibilityRenderObject.cpp:
+ (WebCore::AccessibilityRenderObject::accessibilityDescription):
+ * dom/DocumentOrderedMap.cpp:
+ (WebCore::keyMatchesId):
+ * dom/Element.h:
+ (Element):
+ (WebCore::Element::getIdAttribute):
+ (WebCore):
+ (WebCore::Element::getNameAttribute):
+ * dom/NameNodeList.cpp:
+ (WebCore::NameNodeList::nodeMatches):
+ * dom/StaticHashSetNodeList.cpp:
+ (WebCore::StaticHashSetNodeList::itemWithName):
+ * dom/StaticNodeList.cpp:
+ (WebCore::StaticNodeList::itemWithName):
+ * html/HTMLAnchorElement.cpp:
+ (WebCore::HTMLAnchorElement::name):
+ * html/HTMLAppletElement.cpp:
+ (WebCore::HTMLAppletElement::createRenderer):
+ * html/HTMLCollection.cpp:
+ (WebCore::HTMLCollection::checkForNameMatch):
+ (WebCore::HTMLCollection::updateNameCache):
+ * html/HTMLEmbedElement.cpp:
+ (WebCore::HTMLEmbedElement::updateWidget):
+ * html/HTMLFormCollection.cpp:
+ (WebCore::HTMLFormCollection::updateNameCache):
+ * html/HTMLFormControlElement.cpp:
+ (WebCore::HTMLFormControlElement::formControlName):
+ * html/HTMLFormElement.cpp:
+ (WebCore::HTMLFormElement::name):
+ * html/HTMLFrameElementBase.cpp:
+ (WebCore::HTMLFrameElementBase::setNameAndOpenURL):
+ * html/HTMLMetaElement.cpp:
+ (WebCore::HTMLMetaElement::name):
+ * html/HTMLNameCollection.cpp:
+ (WebCore::HTMLNameCollection::itemAfter):
+ * html/HTMLObjectElement.cpp:
+ (WebCore::HTMLObjectElement::updateWidget):
+ (WebCore::HTMLObjectElement::updateDocNamedItem):
+ (WebCore::HTMLObjectElement::containsJavaApplet):
+ (WebCore::HTMLObjectElement::formControlName):
+ * inspector/InspectorPageAgent.cpp:
+ (WebCore::InspectorPageAgent::buildObjectForFrame):
+ * page/Frame.cpp:
+ (WebCore::Frame::matchLabelsAgainstElement):
+ * rendering/svg/RenderSVGResourceContainer.cpp:
+ (WebCore::RenderSVGResourceContainer::RenderSVGResourceContainer):
+ * svg/SVGSVGElement.cpp:
+ (WebCore::SVGSVGElement::getElementById):
+
2012-02-11 Sheriff Bot <webkit.review....@gmail.com>
Unreviewed, rolling out r107435.
Modified: trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp (107476 => 107477)
--- trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp 2012-02-11 08:56:19 UTC (rev 107476)
+++ trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp 2012-02-11 14:50:28 UTC (rev 107477)
@@ -1428,14 +1428,14 @@
const AtomicString& title = static_cast<HTMLFrameElementBase*>(owner)->getAttribute(titleAttr);
if (!title.isEmpty())
return title;
- return static_cast<HTMLFrameElementBase*>(owner)->getAttribute(nameAttr);
+ return static_cast<HTMLFrameElementBase*>(owner)->getNameAttribute();
}
if (owner->isHTMLElement())
- return toHTMLElement(owner)->getAttribute(nameAttr);
+ return toHTMLElement(owner)->getNameAttribute();
}
owner = document->body();
if (owner && owner->isHTMLElement())
- return toHTMLElement(owner)->getAttribute(nameAttr);
+ return toHTMLElement(owner)->getNameAttribute();
}
return String();
Modified: trunk/Source/WebCore/dom/DocumentOrderedMap.cpp (107476 => 107477)
--- trunk/Source/WebCore/dom/DocumentOrderedMap.cpp 2012-02-11 08:56:19 UTC (rev 107476)
+++ trunk/Source/WebCore/dom/DocumentOrderedMap.cpp 2012-02-11 14:50:28 UTC (rev 107477)
@@ -42,7 +42,7 @@
inline bool keyMatchesId(AtomicStringImpl* key, Element* element)
{
- return element->hasID() && element->getIdAttribute().impl() == key;
+ return element->getIdAttribute().impl() == key;
}
inline bool keyMatchesMapName(AtomicStringImpl* key, Element* element)
Modified: trunk/Source/WebCore/dom/Element.h (107476 => 107477)
--- trunk/Source/WebCore/dom/Element.h 2012-02-11 08:56:19 UTC (rev 107476)
+++ trunk/Source/WebCore/dom/Element.h 2012-02-11 14:50:28 UTC (rev 107477)
@@ -147,6 +147,8 @@
const AtomicString& getIdAttribute() const;
void setIdAttribute(const AtomicString&);
+ const AtomicString& getNameAttribute() const;
+
// Call this to get the value of the id attribute for style resolution purposes.
// The value will already be lowercased if the document is in compatibility mode,
// so this function is not suitable for non-style uses.
@@ -628,9 +630,14 @@
inline const AtomicString& Element::getIdAttribute() const
{
- return fastGetAttribute(document()->idAttributeName());
+ return hasID() ? fastGetAttribute(document()->idAttributeName()) : nullAtom;
}
+inline const AtomicString& Element::getNameAttribute() const
+{
+ return hasName() ? fastGetAttribute(HTMLNames::nameAttr) : nullAtom;
+}
+
inline void Element::setIdAttribute(const AtomicString& value)
{
setAttribute(document()->idAttributeName(), value);
Modified: trunk/Source/WebCore/dom/NameNodeList.cpp (107476 => 107477)
--- trunk/Source/WebCore/dom/NameNodeList.cpp 2012-02-11 08:56:19 UTC (rev 107476)
+++ trunk/Source/WebCore/dom/NameNodeList.cpp 2012-02-11 14:50:28 UTC (rev 107477)
@@ -44,7 +44,7 @@
bool NameNodeList::nodeMatches(Element* testNode) const
{
- return testNode->fastGetAttribute(nameAttr) == m_nodeName;
+ return testNode->getNameAttribute() == m_nodeName;
}
} // namespace WebCore
Modified: trunk/Source/WebCore/dom/StaticHashSetNodeList.cpp (107476 => 107477)
--- trunk/Source/WebCore/dom/StaticHashSetNodeList.cpp 2012-02-11 08:56:19 UTC (rev 107476)
+++ trunk/Source/WebCore/dom/StaticHashSetNodeList.cpp 2012-02-11 14:50:28 UTC (rev 107477)
@@ -69,7 +69,7 @@
ListHashSet<RefPtr<Node> >::const_iterator end = m_nodes.end();
for ( ; it != end ; ++it) {
Node* node = (*it).get();
- if (node->hasID() && static_cast<Element*>(node)->getIdAttribute() == elementId)
+ if (static_cast<Element*>(node)->getIdAttribute() == elementId)
return node;
}
Modified: trunk/Source/WebCore/dom/StaticNodeList.cpp (107476 => 107477)
--- trunk/Source/WebCore/dom/StaticNodeList.cpp 2012-02-11 08:56:19 UTC (rev 107476)
+++ trunk/Source/WebCore/dom/StaticNodeList.cpp 2012-02-11 14:50:28 UTC (rev 107477)
@@ -50,8 +50,7 @@
size_t length = m_nodes.size();
for (size_t i = 0; i < length; ++i) {
Node* node = m_nodes[i].get();
- // FIXME: This should probably be using getIdAttribute instead of idForStyleResolution.
- if (node->hasID() && static_cast<Element*>(node)->getIdAttribute() == elementId)
+ if (static_cast<Element*>(node)->getIdAttribute() == elementId)
return node;
}
Modified: trunk/Source/WebCore/html/HTMLAnchorElement.cpp (107476 => 107477)
--- trunk/Source/WebCore/html/HTMLAnchorElement.cpp 2012-02-11 08:56:19 UTC (rev 107476)
+++ trunk/Source/WebCore/html/HTMLAnchorElement.cpp 2012-02-11 14:50:28 UTC (rev 107477)
@@ -293,7 +293,7 @@
const AtomicString& HTMLAnchorElement::name() const
{
- return getAttribute(nameAttr);
+ return getNameAttribute();
}
short HTMLAnchorElement::tabIndex() const
Modified: trunk/Source/WebCore/html/HTMLAppletElement.cpp (107476 => 107477)
--- trunk/Source/WebCore/html/HTMLAppletElement.cpp 2012-02-11 08:56:19 UTC (rev 107476)
+++ trunk/Source/WebCore/html/HTMLAppletElement.cpp 2012-02-11 14:50:28 UTC (rev 107477)
@@ -78,7 +78,7 @@
if (!codeBase.isNull())
args.set("codeBase", codeBase);
- const AtomicString& name = document()->isHTMLDocument() ? getAttribute(nameAttr) : getIdAttribute();
+ const AtomicString& name = document()->isHTMLDocument() ? getNameAttribute() : getIdAttribute();
if (!name.isNull())
args.set("name", name);
const AtomicString& archive = getAttribute(archiveAttr);
Modified: trunk/Source/WebCore/html/HTMLCollection.cpp (107476 => 107477)
--- trunk/Source/WebCore/html/HTMLCollection.cpp 2012-02-11 08:56:19 UTC (rev 107476)
+++ trunk/Source/WebCore/html/HTMLCollection.cpp 2012-02-11 14:50:28 UTC (rev 107477)
@@ -254,7 +254,7 @@
if (m_type == DocAll && !nameShouldBeVisibleInDocumentAll(e))
return false;
- return e->getAttribute(nameAttr) == name && e->getIdAttribute() != name;
+ return e->getNameAttribute() == name && e->getIdAttribute() != name;
}
Node* HTMLCollection::namedItem(const AtomicString& name) const
@@ -294,7 +294,7 @@
continue;
HTMLElement* e = toHTMLElement(element);
const AtomicString& idAttrVal = e->getIdAttribute();
- const AtomicString& nameAttrVal = e->getAttribute(nameAttr);
+ const AtomicString& nameAttrVal = e->getNameAttribute();
if (!idAttrVal.isEmpty())
append(m_cache.idCache, idAttrVal, e);
if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal && (m_type != DocAll || nameShouldBeVisibleInDocumentAll(e)))
Modified: trunk/Source/WebCore/html/HTMLEmbedElement.cpp (107476 => 107477)
--- trunk/Source/WebCore/html/HTMLEmbedElement.cpp 2012-02-11 08:56:19 UTC (rev 107476)
+++ trunk/Source/WebCore/html/HTMLEmbedElement.cpp 2012-02-11 14:50:28 UTC (rev 107477)
@@ -164,7 +164,7 @@
SubframeLoader* loader = document()->frame()->loader()->subframeLoader();
// FIXME: beforeLoad could have detached the renderer! Just like in the <object> case above.
- loader->requestObject(this, m_url, getAttribute(nameAttr), m_serviceType, paramNames, paramValues);
+ loader->requestObject(this, m_url, getNameAttribute(), m_serviceType, paramNames, paramValues);
}
bool HTMLEmbedElement::rendererIsNeeded(const NodeRenderingContext& context)
Modified: trunk/Source/WebCore/html/HTMLFormCollection.cpp (107476 => 107477)
--- trunk/Source/WebCore/html/HTMLFormCollection.cpp 2012-02-11 08:56:19 UTC (rev 107476)
+++ trunk/Source/WebCore/html/HTMLFormCollection.cpp 2012-02-11 14:50:28 UTC (rev 107477)
@@ -164,7 +164,7 @@
if (associatedElement->isEnumeratable()) {
HTMLElement* element = toHTMLElement(associatedElement);
const AtomicString& idAttrVal = element->getIdAttribute();
- const AtomicString& nameAttrVal = element->getAttribute(nameAttr);
+ const AtomicString& nameAttrVal = element->getNameAttribute();
if (!idAttrVal.isEmpty()) {
append(m_cache.idCache, idAttrVal, element);
foundInputElements.add(idAttrVal.impl());
@@ -179,7 +179,7 @@
for (unsigned i = 0; i < f->m_imageElements.size(); ++i) {
HTMLImageElement* element = f->m_imageElements[i];
const AtomicString& idAttrVal = element->getIdAttribute();
- const AtomicString& nameAttrVal = element->getAttribute(nameAttr);
+ const AtomicString& nameAttrVal = element->getNameAttribute();
if (!idAttrVal.isEmpty() && !foundInputElements.contains(idAttrVal.impl()))
append(m_cache.idCache, idAttrVal, element);
if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal && !foundInputElements.contains(nameAttrVal.impl()))
Modified: trunk/Source/WebCore/html/HTMLFormControlElement.cpp (107476 => 107477)
--- trunk/Source/WebCore/html/HTMLFormControlElement.cpp 2012-02-11 08:56:19 UTC (rev 107476)
+++ trunk/Source/WebCore/html/HTMLFormControlElement.cpp 2012-02-11 14:50:28 UTC (rev 107477)
@@ -227,7 +227,7 @@
const AtomicString& HTMLFormControlElement::formControlName() const
{
- const AtomicString& name = fastGetAttribute(nameAttr);
+ const AtomicString& name = getNameAttribute();
return name.isNull() ? emptyAtom : name;
}
Modified: trunk/Source/WebCore/html/HTMLFormElement.cpp (107476 => 107477)
--- trunk/Source/WebCore/html/HTMLFormElement.cpp 2012-02-11 08:56:19 UTC (rev 107476)
+++ trunk/Source/WebCore/html/HTMLFormElement.cpp 2012-02-11 14:50:28 UTC (rev 107477)
@@ -500,7 +500,7 @@
String HTMLFormElement::name() const
{
- return getAttribute(nameAttr);
+ return getNameAttribute();
}
bool HTMLFormElement::noValidate() const
Modified: trunk/Source/WebCore/html/HTMLFrameElementBase.cpp (107476 => 107477)
--- trunk/Source/WebCore/html/HTMLFrameElementBase.cpp 2012-02-11 08:56:19 UTC (rev 107476)
+++ trunk/Source/WebCore/html/HTMLFrameElementBase.cpp 2012-02-11 14:50:28 UTC (rev 107477)
@@ -174,7 +174,7 @@
void HTMLFrameElementBase::setNameAndOpenURL()
{
- m_frameName = getAttribute(nameAttr);
+ m_frameName = getNameAttribute();
if (m_frameName.isNull())
m_frameName = getIdAttribute();
openURL();
Modified: trunk/Source/WebCore/html/HTMLMetaElement.cpp (107476 => 107477)
--- trunk/Source/WebCore/html/HTMLMetaElement.cpp 2012-02-11 08:56:19 UTC (rev 107476)
+++ trunk/Source/WebCore/html/HTMLMetaElement.cpp 2012-02-11 14:50:28 UTC (rev 107477)
@@ -94,7 +94,7 @@
String HTMLMetaElement::name() const
{
- return getAttribute(nameAttr);
+ return getNameAttribute();
}
#if ENABLE(MICRODATA)
Modified: trunk/Source/WebCore/html/HTMLNameCollection.cpp (107476 => 107477)
--- trunk/Source/WebCore/html/HTMLNameCollection.cpp 2012-02-11 08:56:19 UTC (rev 107476)
+++ trunk/Source/WebCore/html/HTMLNameCollection.cpp 2012-02-11 14:50:28 UTC (rev 107477)
@@ -61,7 +61,7 @@
e->hasTagName(appletTag) ||
e->hasTagName(embedTag) ||
e->hasTagName(objectTag))
- if (e->getAttribute(nameAttr) == m_name)
+ if (e->getNameAttribute() == m_name)
return e;
if (e->getIdAttribute() == m_name)
return e;
@@ -71,17 +71,17 @@
// applets and object by id, and images by id but only if they have
// a name attribute (this very strange rule matches IE)
if (e->hasTagName(formTag) || e->hasTagName(embedTag) || e->hasTagName(iframeTag)) {
- if (e->getAttribute(nameAttr) == m_name)
+ if (e->getNameAttribute() == m_name)
return e;
} else if (e->hasTagName(appletTag)) {
- if (e->getAttribute(nameAttr) == m_name || e->getIdAttribute() == m_name)
+ if (e->getNameAttribute() == m_name || e->getIdAttribute() == m_name)
return e;
} else if (e->hasTagName(objectTag)) {
- if ((e->getAttribute(nameAttr) == m_name || e->getIdAttribute() == m_name)
+ if ((e->getNameAttribute() == m_name || e->getIdAttribute() == m_name)
&& static_cast<HTMLObjectElement*>(e)->isDocNamedItem())
return e;
} else if (e->hasTagName(imgTag)) {
- if (e->getAttribute(nameAttr) == m_name || (e->getIdAttribute() == m_name && e->hasAttribute(nameAttr)))
+ if (e->getNameAttribute() == m_name || (e->getIdAttribute() == m_name && e->hasName()))
return e;
}
break;
Modified: trunk/Source/WebCore/html/HTMLObjectElement.cpp (107476 => 107477)
--- trunk/Source/WebCore/html/HTMLObjectElement.cpp 2012-02-11 08:56:19 UTC (rev 107476)
+++ trunk/Source/WebCore/html/HTMLObjectElement.cpp 2012-02-11 14:50:28 UTC (rev 107477)
@@ -300,7 +300,7 @@
return;
SubframeLoader* loader = document()->frame()->loader()->subframeLoader();
- bool success = beforeLoadAllowedLoad && hasValidClassId() && loader->requestObject(this, url, getAttribute(nameAttr), serviceType, paramNames, paramValues);
+ bool success = beforeLoadAllowedLoad && hasValidClassId() && loader->requestObject(this, url, getNameAttribute(), serviceType, paramNames, paramValues);
if (!success && fallbackContent)
renderFallbackContent();
}
@@ -423,10 +423,10 @@
if (isNamedItem != wasNamedItem && document()->isHTMLDocument()) {
HTMLDocument* document = static_cast<HTMLDocument*>(this->document());
if (isNamedItem) {
- document->addNamedItem(fastGetAttribute(nameAttr));
+ document->addNamedItem(getNameAttribute());
document->addExtraNamedItem(getIdAttribute());
} else {
- document->removeNamedItem(fastGetAttribute(nameAttr));
+ document->removeNamedItem(getNameAttribute());
document->removeExtraNamedItem(getIdAttribute());
}
}
@@ -440,7 +440,7 @@
for (Element* child = firstElementChild(); child; child = child->nextElementSibling()) {
if (child->hasTagName(paramTag)
- && equalIgnoringCase(child->getAttribute(nameAttr), "type")
+ && equalIgnoringCase(child->getNameAttribute(), "type")
&& MIMETypeRegistry::isJavaAppletMIMEType(child->getAttribute(valueAttr).string()))
return true;
if (child->hasTagName(objectTag)
@@ -501,7 +501,7 @@
const AtomicString& HTMLObjectElement::formControlName() const
{
- const AtomicString& name = fastGetAttribute(nameAttr);
+ const AtomicString& name = getNameAttribute();
return name.isNull() ? emptyAtom : name;
}
Modified: trunk/Source/WebCore/inspector/InspectorPageAgent.cpp (107476 => 107477)
--- trunk/Source/WebCore/inspector/InspectorPageAgent.cpp 2012-02-11 08:56:19 UTC (rev 107476)
+++ trunk/Source/WebCore/inspector/InspectorPageAgent.cpp 2012-02-11 14:50:28 UTC (rev 107477)
@@ -732,7 +732,7 @@
if (frame->tree()->parent())
frameObject->setString("parentId", frameId(frame->tree()->parent()));
if (frame->ownerElement()) {
- String name = frame->ownerElement()->getAttribute(HTMLNames::nameAttr);
+ String name = frame->ownerElement()->getNameAttribute();
if (name.isEmpty())
name = frame->ownerElement()->getAttribute(HTMLNames::idAttr);
frameObject->setString("name", name);
Modified: trunk/Source/WebCore/page/Frame.cpp (107476 => 107477)
--- trunk/Source/WebCore/page/Frame.cpp 2012-02-11 08:56:19 UTC (rev 107476)
+++ trunk/Source/WebCore/page/Frame.cpp 2012-02-11 14:50:28 UTC (rev 107477)
@@ -481,7 +481,7 @@
// See 7538330 for one popular site that benefits from the id element check.
// FIXME: This code is mirrored in FrameMac.mm. It would be nice to make the Mac code call the platform-agnostic
// code, which would require converting the NSArray of NSStrings to a Vector of Strings somewhere along the way.
- String resultFromNameAttribute = matchLabelsAgainstString(labels, element->getAttribute(nameAttr));
+ String resultFromNameAttribute = matchLabelsAgainstString(labels, element->getNameAttribute());
if (!resultFromNameAttribute.isEmpty())
return resultFromNameAttribute;
Modified: trunk/Source/WebCore/rendering/svg/RenderSVGResourceContainer.cpp (107476 => 107477)
--- trunk/Source/WebCore/rendering/svg/RenderSVGResourceContainer.cpp 2012-02-11 08:56:19 UTC (rev 107476)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGResourceContainer.cpp 2012-02-11 14:50:28 UTC (rev 107477)
@@ -38,7 +38,7 @@
RenderSVGResourceContainer::RenderSVGResourceContainer(SVGStyledElement* node)
: RenderSVGHiddenContainer(node)
- , m_id(node->hasID() ? node->getIdAttribute() : nullAtom)
+ , m_id(node->getIdAttribute())
, m_registered(false)
, m_isInvalidating(false)
{
Modified: trunk/Source/WebCore/svg/SVGSVGElement.cpp (107476 => 107477)
--- trunk/Source/WebCore/svg/SVGSVGElement.cpp 2012-02-11 08:56:19 UTC (rev 107476)
+++ trunk/Source/WebCore/svg/SVGSVGElement.cpp 2012-02-11 14:50:28 UTC (rev 107477)
@@ -726,7 +726,7 @@
continue;
Element* element = static_cast<Element*>(node);
- if (element->hasID() && element->getIdAttribute() == id)
+ if (element->getIdAttribute() == id)
return element;
}
return 0;