[SCM] WebKit Debian packaging branch, webkit-1.2, updated. upstream/1.1.90-6072-g9a69373
snej at chromium.org
snej at chromium.org
Wed Apr 7 23:29:41 UTC 2010
The following commit has been merged in the webkit-1.2 branch:
commit bd1092985052d851cb7a65c2e1ce259fd74931ad
Author: snej at chromium.org <snej at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Tue Nov 10 22:03:20 2009 +0000
Optimizations to Element::getAttribute
https://bugs.webkit.org/show_bug.cgi?id=30926
Reviewed by Darin Adler.
* dom/Element.cpp:
(WebCore::Element::getAttribute): User case-insensitive compare instead of lowercasing the name.
* dom/NamedAttrMap.cpp:
(WebCore::NamedNodeMap::getAttributeItem): Avoid redundant compares, and do fast/likely compares first.
* platform/text/PlatformString.h:
(WebCore::equalPossiblyIgnoringCase): New inline method, used by both of the above.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@50763 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index a3305f0..ce64824 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,17 @@
+2009-11-10 Jens Alfke <snej at chromium.org>
+
+ Reviewed by Darin Adler.
+
+ Optimizations to Element::getAttribute
+ https://bugs.webkit.org/show_bug.cgi?id=30926
+
+ * dom/Element.cpp:
+ (WebCore::Element::getAttribute): User case-insensitive compare instead of lowercasing the name.
+ * dom/NamedAttrMap.cpp:
+ (WebCore::NamedNodeMap::getAttributeItem): Avoid redundant compares, and do fast/likely compares first.
+ * platform/text/PlatformString.h:
+ (WebCore::equalPossiblyIgnoringCase): New inline method, used by both of the above.
+
2009-11-10 Beth Dakin <bdakin at apple.com>
Reviewed by Darin Adler.
diff --git a/WebCore/dom/Element.cpp b/WebCore/dom/Element.cpp
index 8513b26..4ade439 100644
--- a/WebCore/dom/Element.cpp
+++ b/WebCore/dom/Element.cpp
@@ -489,8 +489,10 @@ static inline bool shouldIgnoreAttributeCase(const Element* e)
const AtomicString& Element::getAttribute(const String& name) const
{
- String localName = shouldIgnoreAttributeCase(this) ? name.lower() : name;
- if (localName == styleAttr.localName() && !m_isStyleAttributeValid)
+ bool ignoreCase = shouldIgnoreAttributeCase(this);
+
+ // Update the 'style' attribute if it's invalid and being requested:
+ if (!m_isStyleAttributeValid && equalPossiblyIgnoringCase(name, styleAttr.localName(), ignoreCase))
updateStyleAttribute();
#if ENABLE(SVG)
@@ -499,8 +501,8 @@ const AtomicString& Element::getAttribute(const String& name) const
#endif
if (namedAttrMap)
- if (Attribute* a = namedAttrMap->getAttributeItem(name, shouldIgnoreAttributeCase(this)))
- return a->value();
+ if (Attribute* attribute = namedAttrMap->getAttributeItem(name, ignoreCase))
+ return attribute->value();
return nullAtom;
}
diff --git a/WebCore/dom/NamedAttrMap.cpp b/WebCore/dom/NamedAttrMap.cpp
index d4ec598..56b40b9 100644
--- a/WebCore/dom/NamedAttrMap.cpp
+++ b/WebCore/dom/NamedAttrMap.cpp
@@ -177,11 +177,33 @@ PassRefPtr<Node> NamedNodeMap::item(unsigned index) const
Attribute* NamedNodeMap::getAttributeItem(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.
for (unsigned i = 0; i < len; ++i) {
- if (!m_attributes[i]->name().hasPrefix() && m_attributes[i]->name().localName() == name)
- return m_attributes[i].get();
- if (shouldIgnoreAttributeCase ? equalIgnoringCase(m_attributes[i]->name().toString(), name) : name == m_attributes[i]->name().toString())
- return m_attributes[i].get();
+ const QualifiedName& attrName = m_attributes[i]->name();
+ if (!attrName.hasPrefix()) {
+ if (name == attrName.localName())
+ 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;
}
diff --git a/WebCore/platform/text/PlatformString.h b/WebCore/platform/text/PlatformString.h
index ea47d8e..247536a 100644
--- a/WebCore/platform/text/PlatformString.h
+++ b/WebCore/platform/text/PlatformString.h
@@ -286,6 +286,11 @@ inline bool equalIgnoringCase(const String& a, const String& b) { return equalIg
inline bool equalIgnoringCase(const String& a, const char* b) { return equalIgnoringCase(a.impl(), b); }
inline bool equalIgnoringCase(const char* a, const String& b) { return equalIgnoringCase(a, b.impl()); }
+inline bool equalPossiblyIgnoringCase(const String& a, const String& b, bool ignoreCase)
+{
+ return ignoreCase ? equalIgnoringCase(a, b) : (a == b);
+}
+
inline bool equalIgnoringNullity(const String& a, const String& b) { return equalIgnoringNullity(a.impl(), b.impl()); }
inline bool operator!(const String& str) { return str.isNull(); }
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list