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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « Source/core/dom/Element.h ('k') | Source/core/dom/Element.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Peter Kelly (pmk@post.com) 4 * (C) 2001 Peter Kelly (pmk@post.com)
5 * (C) 2001 Dirk Mueller (mueller@kde.org) 5 * (C) 2001 Dirk Mueller (mueller@kde.org)
6 * (C) 2007 David Smith (catfish.man@gmail.com) 6 * (C) 2007 David Smith (catfish.man@gmail.com)
7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved. 7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved.
8 * (C) 2007 Eric Seidel (eric@webkit.org) 8 * (C) 2007 Eric Seidel (eric@webkit.org)
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 } 901 }
902 902
903 IntRect Element::screenRect() const 903 IntRect Element::screenRect() const
904 { 904 {
905 if (!renderer()) 905 if (!renderer())
906 return IntRect(); 906 return IntRect();
907 // FIXME: this should probably respect transforms 907 // FIXME: this should probably respect transforms
908 return document().view()->contentsToScreen(renderer()->absoluteBoundingBoxRe ctIgnoringTransforms()); 908 return document().view()->contentsToScreen(renderer()->absoluteBoundingBoxRe ctIgnoringTransforms());
909 } 909 }
910 910
911 namespace {
912 enum CallerType {
913 Getter,
914 Setter
915 };
916
917 template<CallerType caller> static inline const QualifiedName& fastAttributeName FromString(const Element& element, const String& localName)
918 {
919 unsigned length = localName.length();
920 if (!length)
921 return nullQName();
922 const StringImpl& name = *localName.impl();
923
924 if (length == 2 && name[0] == 'i' && name[1] == 'd')
925 return HTMLNames::idAttr;
926 if (length == 4 && name[0] == 'n' && name[1] == 'a' && name[2] == 'm' && nam e[3] == 'e')
927 return HTMLNames::nameAttr;
928 if ((caller == Setter || !element.isSVGElement()) && length == 5 && name[0] == 'c' && name[1] == 'l' && name[2] == 'a' && name[3] == 's' && name[4] == 's')
929 return HTMLNames::classAttr;
930 if (caller == Setter && length == 5 && name[0] == 's' && name[1] == 't' && n ame[2] == 'y' && name[3] == 'l' && name[4] == 'e')
931 return HTMLNames::styleAttr;
932
933 return nullQName();
934 }
935 }
936
937 const AtomicString& Element::bindingsGetAttribute(const String& localName) const
938 {
939 const QualifiedName& fastName = fastAttributeNameFromString<Getter>(*this, l ocalName);
940 if (fastName != nullQName())
941 return fastGetAttribute(fastName);
942 return getAttribute(AtomicString(localName));
943 }
944
945 void Element::bindingsSetAttribute(const String& localName, const AtomicString& newValue, ExceptionState& exceptionState)
946 {
947 const QualifiedName& fastName = fastAttributeNameFromString<Setter>(*this, l ocalName);
948 if (fastName != nullQName()) {
949 setAttribute(fastName, newValue);
950 return;
951 }
952 setAttribute(AtomicString(localName), newValue, exceptionState);
953 }
954
911 const AtomicString& Element::getAttribute(const AtomicString& localName) const 955 const AtomicString& Element::getAttribute(const AtomicString& localName) const
912 { 956 {
913 if (!elementData()) 957 if (!elementData())
914 return nullAtom; 958 return nullAtom;
915 synchronizeAttribute(localName); 959 synchronizeAttribute(localName);
916 if (const Attribute* attribute = elementData()->getAttributeItem(localName, shouldIgnoreAttributeCase())) 960 if (const Attribute* attribute = elementData()->getAttributeItem(localName, shouldIgnoreAttributeCase()))
917 return attribute->value(); 961 return attribute->value();
918 return nullAtom; 962 return nullAtom;
919 } 963 }
920 964
(...skipping 2619 matching lines...) Expand 10 before | Expand all | Expand 10 after
3540 // Before doing so, we need to resolve issues in HTMLSelectElement::recalcLi stItems 3584 // Before doing so, we need to resolve issues in HTMLSelectElement::recalcLi stItems
3541 // and RenderMenuList::setText. See also https://bugs.webkit.org/show_bug.cg i?id=88405 3585 // and RenderMenuList::setText. See also https://bugs.webkit.org/show_bug.cg i?id=88405
3542 if (hasTagName(optionTag) || hasTagName(optgroupTag)) 3586 if (hasTagName(optionTag) || hasTagName(optgroupTag))
3543 return false; 3587 return false;
3544 if (FullscreenElementStack::isActiveFullScreenElement(this)) 3588 if (FullscreenElementStack::isActiveFullScreenElement(this))
3545 return false; 3589 return false;
3546 return true; 3590 return true;
3547 } 3591 }
3548 3592
3549 } // namespace WebCore 3593 } // namespace WebCore
OLDNEW
« 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