Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(563)

Unified Diff: Source/core/dom/Element.cpp

Issue 189483004: WontFix: Add fast path for id/name/style/class in getAttribute/setAttribute bindings. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add performance tests about rare attribute. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/dom/Element.h ('k') | Source/core/dom/Element.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/Element.cpp
diff --git a/Source/core/dom/Element.cpp b/Source/core/dom/Element.cpp
index bb3e0aad6f5ef42a05593dfba29040649ea60d5c..c6a0edab66f32e92e4f95083385e3f8388168ee5 100644
--- a/Source/core/dom/Element.cpp
+++ b/Source/core/dom/Element.cpp
@@ -908,6 +908,50 @@ IntRect Element::screenRect() const
return document().view()->contentsToScreen(renderer()->absoluteBoundingBoxRectIgnoringTransforms());
}
+namespace {
+enum CallerType {
+ Getter,
+ Setter
+};
+
+template<CallerType caller> static inline const QualifiedName& fastAttributeNameFromString(const Element& element, const String& localName)
+{
+ unsigned length = localName.length();
+ if (!length)
+ return nullQName();
+ const StringImpl& name = *localName.impl();
+
+ if (length == 2 && name[0] == 'i' && name[1] == 'd')
+ return HTMLNames::idAttr;
+ if (length == 4 && name[0] == 'n' && name[1] == 'a' && name[2] == 'm' && name[3] == 'e')
+ return HTMLNames::nameAttr;
+ if ((caller == Setter || !element.isSVGElement()) && length == 5 && name[0] == 'c' && name[1] == 'l' && name[2] == 'a' && name[3] == 's' && name[4] == 's')
+ return HTMLNames::classAttr;
+ if (caller == Setter && length == 5 && name[0] == 's' && name[1] == 't' && name[2] == 'y' && name[3] == 'l' && name[4] == 'e')
+ return HTMLNames::styleAttr;
+
+ return nullQName();
+}
+}
+
+const AtomicString& Element::bindingsGetAttribute(const String& localName) const
+{
+ const QualifiedName& fastName = fastAttributeNameFromString<Getter>(*this, localName);
+ if (fastName != nullQName())
+ return fastGetAttribute(fastName);
+ return getAttribute(AtomicString(localName));
+}
+
+void Element::bindingsSetAttribute(const String& localName, const AtomicString& newValue, ExceptionState& exceptionState)
+{
+ const QualifiedName& fastName = fastAttributeNameFromString<Setter>(*this, localName);
+ if (fastName != nullQName()) {
+ setAttribute(fastName, newValue);
+ return;
+ }
+ setAttribute(AtomicString(localName), newValue, exceptionState);
+}
+
const AtomicString& Element::getAttribute(const AtomicString& localName) const
{
if (!elementData())
« no previous file with comments | « Source/core/dom/Element.h ('k') | Source/core/dom/Element.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698