Commit f8fd7445 authored by ch.dumez@samsung.com's avatar ch.dumez@samsung.com

Avoid calling hasAttribute() and then getAttribute() for performance

Avoid calling hasAttribute() and then getAttribute() for performance.
This causes the attribute to be looked up (linear search) twice instead
of once if we call getAttribute() directly and then check if the returned
AtomicString is null.

R=eseidel@chromium.org, eseidel, rwlbuis

Review URL: https://codereview.chromium.org/183763033

git-svn-id: svn://svn.chromium.org/blink/trunk@168423 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent ecc619e3
...@@ -290,12 +290,13 @@ void HTMLAttributeEquivalent::addToStyle(Element* element, EditingStyle* style) ...@@ -290,12 +290,13 @@ void HTMLAttributeEquivalent::addToStyle(Element* element, EditingStyle* style)
PassRefPtrWillBeRawPtr<CSSValue> HTMLAttributeEquivalent::attributeValueAsCSSValue(Element* element) const PassRefPtrWillBeRawPtr<CSSValue> HTMLAttributeEquivalent::attributeValueAsCSSValue(Element* element) const
{ {
ASSERT(element); ASSERT(element);
if (!element->hasAttribute(m_attrName)) const AtomicString& value = element->getAttribute(m_attrName);
if (value.isNull())
return nullptr; return nullptr;
RefPtr<MutableStylePropertySet> dummyStyle; RefPtr<MutableStylePropertySet> dummyStyle;
dummyStyle = MutableStylePropertySet::create(); dummyStyle = MutableStylePropertySet::create();
dummyStyle->setProperty(m_propertyID, element->getAttribute(m_attrName)); dummyStyle->setProperty(m_propertyID, value);
return dummyStyle->getPropertyCSSValue(m_propertyID); return dummyStyle->getPropertyCSSValue(m_propertyID);
} }
...@@ -319,10 +320,11 @@ HTMLFontSizeEquivalent::HTMLFontSizeEquivalent() ...@@ -319,10 +320,11 @@ HTMLFontSizeEquivalent::HTMLFontSizeEquivalent()
PassRefPtrWillBeRawPtr<CSSValue> HTMLFontSizeEquivalent::attributeValueAsCSSValue(Element* element) const PassRefPtrWillBeRawPtr<CSSValue> HTMLFontSizeEquivalent::attributeValueAsCSSValue(Element* element) const
{ {
ASSERT(element); ASSERT(element);
if (!element->hasAttribute(m_attrName)) const AtomicString& value = element->getAttribute(m_attrName);
if (value.isNull())
return nullptr; return nullptr;
CSSValueID size; CSSValueID size;
if (!HTMLFontElement::cssValueFromFontSizeNumber(element->getAttribute(m_attrName), size)) if (!HTMLFontElement::cssValueFromFontSizeNumber(value, size))
return nullptr; return nullptr;
return CSSPrimitiveValue::createIdentifier(size); return CSSPrimitiveValue::createIdentifier(size);
} }
......
...@@ -93,8 +93,9 @@ void SplitElementCommand::doUnapply() ...@@ -93,8 +93,9 @@ void SplitElementCommand::doUnapply()
m_element2->insertBefore(children[i].get(), refChild.get(), IGNORE_EXCEPTION); m_element2->insertBefore(children[i].get(), refChild.get(), IGNORE_EXCEPTION);
// Recover the id attribute of the original element. // Recover the id attribute of the original element.
if (m_element1->hasAttribute(HTMLNames::idAttr)) const AtomicString& id = m_element1->getAttribute(HTMLNames::idAttr);
m_element2->setAttribute(HTMLNames::idAttr, m_element1->getAttribute(HTMLNames::idAttr)); if (!id.isNull())
m_element2->setAttribute(HTMLNames::idAttr, id);
m_element1->remove(IGNORE_EXCEPTION); m_element1->remove(IGNORE_EXCEPTION);
} }
......
...@@ -393,12 +393,13 @@ bool HTMLAnchorElement::isLiveLink() const ...@@ -393,12 +393,13 @@ bool HTMLAnchorElement::isLiveLink() const
void HTMLAnchorElement::sendPings(const KURL& destinationURL) void HTMLAnchorElement::sendPings(const KURL& destinationURL)
{ {
if (!hasAttribute(pingAttr) || !document().settings() || !document().settings()->hyperlinkAuditingEnabled()) const AtomicString& pingValue = getAttribute(pingAttr);
if (pingValue.isNull() || !document().settings() || !document().settings()->hyperlinkAuditingEnabled())
return; return;
UseCounter::count(document(), UseCounter::HTMLAnchorElementPingAttribute); UseCounter::count(document(), UseCounter::HTMLAnchorElementPingAttribute);
SpaceSplitString pingURLs(getAttribute(pingAttr), false); SpaceSplitString pingURLs(pingValue, false);
for (unsigned i = 0; i < pingURLs.size(); i++) for (unsigned i = 0; i < pingURLs.size(); i++)
PingLoader::sendPing(document().frame(), document().completeURL(pingURLs[i]), destinationURL); PingLoader::sendPing(document().frame(), document().completeURL(pingURLs[i]), destinationURL);
} }
......
...@@ -175,9 +175,10 @@ public: ...@@ -175,9 +175,10 @@ public:
virtual bool perform(ExceptionState& exceptionState) OVERRIDE virtual bool perform(ExceptionState& exceptionState) OVERRIDE
{ {
m_hadAttribute = m_element->hasAttribute(m_name); const AtomicString& value = m_element->getAttribute(m_name);
m_hadAttribute = !value.isNull();
if (m_hadAttribute) if (m_hadAttribute)
m_oldValue = m_element->getAttribute(m_name); m_oldValue = value;
return redo(exceptionState); return redo(exceptionState);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment