Chromium Code Reviews| Index: Source/core/dom/Element.cpp |
| diff --git a/Source/core/dom/Element.cpp b/Source/core/dom/Element.cpp |
| index 74d3965142bd8e6dea27cf522c36500443f7d29d..8fd56ce25e2aee01197a80d59522d360f170af5c 100644 |
| --- a/Source/core/dom/Element.cpp |
| +++ b/Source/core/dom/Element.cpp |
| @@ -114,41 +114,6 @@ using namespace HTMLNames; |
| using namespace XMLNames; |
| typedef WillBeHeapVector<RefPtrWillBeMember<Attr> > AttrNodeList; |
| -typedef WillBePersistentHeapHashMap<RawPtrWillBeWeakMember<Element>, OwnPtrWillBeMember<AttrNodeList> > AttrNodeListMap; |
| - |
| -static AttrNodeListMap& attrNodeListMap() |
| -{ |
| - DEFINE_STATIC_LOCAL(AttrNodeListMap, map, ()); |
| - return map; |
| -} |
| - |
| -static AttrNodeList* attrNodeListForElement(Element* element) |
| -{ |
| - if (!element->hasSyntheticAttrChildNodes()) |
| - return 0; |
| - ASSERT(attrNodeListMap().contains(element)); |
| - return attrNodeListMap().get(element); |
| -} |
| - |
| -static AttrNodeList& ensureAttrNodeListForElement(Element* element) |
| -{ |
| - if (element->hasSyntheticAttrChildNodes()) { |
| - ASSERT(attrNodeListMap().contains(element)); |
| - return *attrNodeListMap().get(element); |
| - } |
| - ASSERT(!attrNodeListMap().contains(element)); |
| - element->setHasSyntheticAttrChildNodes(true); |
| - AttrNodeListMap::AddResult result = attrNodeListMap().add(element, adoptPtrWillBeNoop(new AttrNodeList)); |
| - return *result.storedValue->value; |
| -} |
| - |
| -static void removeAttrNodeListForElement(Element* element) |
| -{ |
| - ASSERT(element->hasSyntheticAttrChildNodes()); |
| - ASSERT(attrNodeListMap().contains(element)); |
| - attrNodeListMap().remove(element); |
| - element->setHasSyntheticAttrChildNodes(false); |
| -} |
| static Attr* findAttrNodeInList(const AttrNodeList& attrNodeList, const QualifiedName& name) |
| { |
| @@ -354,12 +319,12 @@ void Element::setBooleanAttribute(const QualifiedName& name, bool value) |
| NamedNodeMap* Element::attributes() const |
| { |
| - ElementRareData& rareData = const_cast<Element*>(this)->ensureElementRareData(); |
| - if (NamedNodeMap* attributeMap = rareData.attributeMap()) |
| + AttrData& attrData = const_cast<Element*>(this)->ensureElementRareData().ensureAttrData(); |
| + if (NamedNodeMap* attributeMap = attrData.attributeMap()) |
| return attributeMap; |
| - rareData.setAttributeMap(NamedNodeMap::create(const_cast<Element*>(this))); |
| - return rareData.attributeMap(); |
| + attrData.setAttributeMap(NamedNodeMap::create(const_cast<Element*>(this))); |
| + return attrData.attributeMap(); |
| } |
| ActiveAnimations* Element::activeAnimations() const |
| @@ -1865,10 +1830,23 @@ void Element::formatForDebugger(char* buffer, unsigned length) const |
| } |
| #endif |
| -const WillBeHeapVector<RefPtrWillBeMember<Attr> >& Element::attrNodeList() |
| +WillBeHeapVector<RefPtrWillBeMember<Attr> >* Element::attrNodeList() |
| +{ |
| + return hasRareData() && elementRareData()->attrData() ? elementRareData()->attrData()->attrNodeList() : 0; |
|
esprehn
2014/06/17 08:27:05
This would be better as:
if (!hasRareData())
re
|
| +} |
| + |
| +WillBeHeapVector<RefPtrWillBeMember<Attr> >& Element::ensureAttrNodeList() |
| +{ |
| + setHasSyntheticAttrChildNodes(true); |
|
esprehn
2014/06/17 08:27:05
You can remove this bitfield now. hasSyntheticAttr
|
| + return ensureElementRareData().ensureAttrData().ensureAttrNodeList(); |
| +} |
| + |
| +void Element::removeAttrNodeList() |
| { |
| ASSERT(hasSyntheticAttrChildNodes()); |
| - return *attrNodeListForElement(this); |
| + if (hasRareData() && elementRareData()->attrData()) |
| + elementRareData()->attrData()->removeAttrNodeList(); |
| + setHasSyntheticAttrChildNodes(false); |
| } |
| PassRefPtrWillBeRawPtr<Attr> Element::setAttributeNode(Attr* attrNode, ExceptionState& exceptionState) |
| @@ -1919,7 +1897,7 @@ PassRefPtrWillBeRawPtr<Attr> Element::setAttributeNode(Attr* attrNode, Exception |
| attrNode->attachToElement(this, localName); |
| treeScope().adoptIfNeeded(*attrNode); |
| - ensureAttrNodeListForElement(this).append(attrNode); |
| + ensureAttrNodeList().append(attrNode); |
| return oldAttrNode.release(); |
| } |
| @@ -2770,7 +2748,7 @@ bool Element::fastAttributeLookupAllowed(const QualifiedName& name) const |
| #ifdef DUMP_NODE_STATISTICS |
| bool Element::hasNamedNodeMap() const |
| { |
| - return hasRareData() && elementRareData()->attributeMap(); |
| + return hasRareData() && elementRareData()->attrData() && elementRareData()->attrData()->attributeMap(); |
|
esprehn
2014/06/17 08:27:05
ditto
|
| } |
| #endif |
| @@ -2985,14 +2963,14 @@ void Element::setSavedLayerScrollOffset(const IntSize& size) |
| PassRefPtrWillBeRawPtr<Attr> Element::attrIfExists(const QualifiedName& name) |
| { |
| - if (AttrNodeList* attrNodeList = attrNodeListForElement(this)) |
| + if (AttrNodeList* attrNodeList = this->attrNodeList()) |
|
haraken
2014/06/17 02:07:02
Rename the |attrNodeList| variable to something el
esprehn
2014/06/17 08:27:05
list = ...
|
| return findAttrNodeInList(*attrNodeList, name); |
| return nullptr; |
| } |
| PassRefPtrWillBeRawPtr<Attr> Element::ensureAttr(const QualifiedName& name) |
| { |
| - AttrNodeList& attrNodeList = ensureAttrNodeListForElement(this); |
| + AttrNodeList& attrNodeList = ensureAttrNodeList(); |
| RefPtrWillBeRawPtr<Attr> attrNode = findAttrNodeInList(attrNodeList, name); |
| if (!attrNode) { |
| attrNode = Attr::create(*this, name); |
| @@ -3007,12 +2985,12 @@ void Element::detachAttrNodeFromElementWithValue(Attr* attrNode, const AtomicStr |
| ASSERT(hasSyntheticAttrChildNodes()); |
| attrNode->detachFromElementWithValue(value); |
| - AttrNodeList* attrNodeList = attrNodeListForElement(this); |
| + AttrNodeList* attrNodeList = this->attrNodeList(); |
| for (unsigned i = 0; i < attrNodeList->size(); ++i) { |
| if (attrNodeList->at(i)->qualifiedName() == attrNode->qualifiedName()) { |
| attrNodeList->remove(i); |
| if (attrNodeList->isEmpty()) |
| - removeAttrNodeListForElement(this); |
| + removeAttrNodeList(); |
| return; |
| } |
| } |
| @@ -3021,7 +2999,7 @@ void Element::detachAttrNodeFromElementWithValue(Attr* attrNode, const AtomicStr |
| void Element::detachAllAttrNodesFromElement() |
| { |
| - AttrNodeList* attrNodeList = attrNodeListForElement(this); |
| + AttrNodeList* attrNodeList = this->attrNodeList(); |
| ASSERT(attrNodeList); |
| AttributeIteratorAccessor attributes = attributesIterator(); |
| @@ -3031,7 +3009,7 @@ void Element::detachAllAttrNodesFromElement() |
| attrNode->detachFromElementWithValue(it->value()); |
| } |
| - removeAttrNodeListForElement(this); |
| + removeAttrNodeList(); |
| } |
| void Element::willRecalcStyle(StyleRecalcChange) |