Changeset 142791 in webkit
- Timestamp:
- Feb 13, 2013 1:48:40 PM (11 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r142788 r142791 1 2013-02-13 Andreas Kling <akling@apple.com> 2 3 Better names for ElementAttributeData & subclasses. 4 <http://webkit.org/b/109529> 5 6 Reviewed by Antti Koivisto. 7 8 - ElementAttributeData => ElementData 9 10 Because ElementAttributeData won't be a good name once we move some non-attribute related 11 things to this structure. 12 13 - ImmutableElementAttributeData => ShareableElementData 14 15 These objects can be shared with other Elements that have the same attribute name/value pairs. 16 17 - MutableElementAttributeData => UniqueElementData 18 19 These objects contain data that is unique to a specific Element, and cannot be shared with 20 other Elements. This is what's important about it, not that its underlying storage is mutable. 21 22 - attributeData() -> elementData() 23 - updatedAttributeData() -> elementDataWithSynchronizedAttributes() 24 - ensureUpdatedAttributeData() -> ensureElementDataWithSynchronizedAttributes() 25 - mutableAttributeData() -> ensureUniqueElementData() 26 27 Ride-along renames. Much less vague than previous names IMO. 28 29 * css/StyleResolver.cpp: 30 (WebCore::StyleResolver::canShareStyleWithControl): 31 (WebCore::StyleResolver::sharingCandidateHasIdenticalStyleAffectingAttributes): 32 * dom/Attr.cpp: 33 (WebCore::Attr::elementAttribute): 34 * dom/DocumentSharedObjectPool.cpp: 35 (WebCore::ShareableElementDataCacheKey::ShareableElementDataCacheKey): 36 (WebCore::ShareableElementDataCacheKey::operator!=): 37 (WebCore::ShareableElementDataCacheEntry::ShareableElementDataCacheEntry): 38 (ShareableElementDataCacheEntry): 39 (WebCore::DocumentSharedObjectPool::cachedShareableElementDataWithAttributes): 40 * dom/DocumentSharedObjectPool.h: 41 (DocumentSharedObjectPool): 42 * dom/Element.cpp: 43 (WebCore::Element::detachAttribute): 44 (WebCore::Element::removeAttribute): 45 (WebCore::Element::attributes): 46 (WebCore::Element::getAttribute): 47 (WebCore::Element::setAttribute): 48 (WebCore::Element::setSynchronizedLazyAttribute): 49 (WebCore::Element::setAttributeInternal): 50 (WebCore::Element::attributeChanged): 51 (WebCore::Element::classAttributeChanged): 52 (WebCore::Element::shouldInvalidateDistributionWhenAttributeChanged): 53 (WebCore::Element::parserSetAttributes): 54 (WebCore::Element::hasAttributes): 55 (WebCore::Element::hasEquivalentAttributes): 56 (WebCore::Element::setAttributeNode): 57 (WebCore::Element::removeAttributeNode): 58 (WebCore::Element::removeAttributeInternal): 59 (WebCore::Element::addAttributeInternal): 60 (WebCore::Element::getAttributeNode): 61 (WebCore::Element::getAttributeNodeNS): 62 (WebCore::Element::hasAttribute): 63 (WebCore::Element::hasAttributeNS): 64 (WebCore::Element::computeInheritedLanguage): 65 (WebCore::Element::getURLAttribute): 66 (WebCore::Element::getNonEmptyURLAttribute): 67 (WebCore::Element::cloneAttributesFromElement): 68 (WebCore::Element::createUniqueElementData): 69 (WebCore::Element::reportMemoryUsage): 70 (WebCore::ElementData::deref): 71 (WebCore::ElementData::ElementData): 72 (WebCore::sizeForShareableElementDataWithAttributeCount): 73 (WebCore::ElementData::createShareableWithAttributes): 74 (WebCore::ElementData::createUnique): 75 (WebCore::ShareableElementData::ShareableElementData): 76 (WebCore::ShareableElementData::~ShareableElementData): 77 (WebCore::UniqueElementData::UniqueElementData): 78 (WebCore::ElementData::makeMutableCopy): 79 (WebCore::ElementData::makeImmutableCopy): 80 (WebCore::ElementData::setPresentationAttributeStyle): 81 (WebCore::ElementData::addAttribute): 82 (WebCore::ElementData::removeAttribute): 83 (WebCore::ElementData::isEquivalent): 84 (WebCore::ElementData::reportMemoryUsage): 85 (WebCore::ElementData::getAttributeItemIndexSlowCase): 86 * dom/Element.h: 87 (ElementData): 88 (WebCore::ElementData::isUnique): 89 (ShareableElementData): 90 (UniqueElementData): 91 (WebCore::Element::getAttributeItemIndex): 92 (WebCore::Element::elementData): 93 (Element): 94 (WebCore::Element::elementDataWithSynchronizedAttributes): 95 (WebCore::Element::ensureElementDataWithSynchronizedAttributes): 96 (WebCore::Element::fastHasAttribute): 97 (WebCore::Element::fastGetAttribute): 98 (WebCore::Element::hasAttributesWithoutUpdate): 99 (WebCore::Element::idForStyleResolution): 100 (WebCore::Element::classNames): 101 (WebCore::Element::attributeCount): 102 (WebCore::Element::attributeItem): 103 (WebCore::Element::getAttributeItem): 104 (WebCore::Element::updateInvalidAttributes): 105 (WebCore::Element::hasID): 106 (WebCore::Element::hasClass): 107 (WebCore::Element::ensureUniqueElementData): 108 (WebCore::ElementData::mutableAttributeVector): 109 (WebCore::ElementData::immutableAttributeArray): 110 (WebCore::ElementData::length): 111 (WebCore::ElementData::presentationAttributeStyle): 112 (WebCore::ElementData::getAttributeItem): 113 (WebCore::ElementData::getAttributeItemIndex): 114 (WebCore::ElementData::attributeItem): 115 * dom/Node.cpp: 116 (WebCore::Node::dumpStatistics): 117 (WebCore::Node::compareDocumentPosition): 118 * dom/StyledElement.cpp: 119 (WebCore::StyledElement::updateStyleAttribute): 120 (WebCore::StyledElement::ensureMutableInlineStyle): 121 (WebCore::StyledElement::attributeChanged): 122 (WebCore::StyledElement::inlineStyleCSSOMWrapper): 123 (WebCore::StyledElement::setInlineStyleFromString): 124 (WebCore::StyledElement::styleAttributeChanged): 125 (WebCore::StyledElement::inlineStyleChanged): 126 (WebCore::StyledElement::addSubresourceAttributeURLs): 127 (WebCore::StyledElement::rebuildPresentationAttributeStyle): 128 * dom/StyledElement.h: 129 (WebCore::StyledElement::inlineStyle): 130 (WebCore::StyledElement::invalidateStyleAttribute): 131 (WebCore::StyledElement::presentationAttributeStyle): 132 * html/ClassList.cpp: 133 (WebCore::ClassList::classNames): 134 * html/HTMLInputElement.cpp: 135 (WebCore::HTMLInputElement::updateType): 136 * html/parser/HTMLConstructionSite.cpp: 137 (WebCore::HTMLConstructionSite::mergeAttributesFromTokenIntoElement): 138 * svg/SVGElement.cpp: 139 (WebCore::SVGElement::updateAnimatedSVGAttribute): 140 * svg/SVGElement.h: 141 (WebCore::SVGElement::invalidateSVGAttributes): 142 * xml/parser/XMLDocumentParserQt.cpp: 143 (WebCore::XMLDocumentParser::XMLDocumentParser): 144 1 145 2013-02-13 Christian Biesinger <cbiesinger@chromium.org> 2 146 -
trunk/Source/WebCore/css/StyleResolver.cpp
r142757 r142791 908 908 return false; 909 909 910 if (thisInputElement-> attributeData() != otherInputElement->attributeData()) {910 if (thisInputElement->elementData() != otherInputElement->elementData()) { 911 911 if (thisInputElement->fastGetAttribute(typeAttr) != otherInputElement->fastGetAttribute(typeAttr)) 912 912 return false; … … 958 958 { 959 959 const State& state = m_state; 960 if (state.element()-> attributeData() == sharingCandidate->attributeData())960 if (state.element()->elementData() == sharingCandidate->elementData()) 961 961 return true; 962 962 if (state.element()->fastGetAttribute(XMLNames::langAttr) != sharingCandidate->fastGetAttribute(XMLNames::langAttr)) -
trunk/Source/WebCore/dom/Attr.cpp
r141935 r142791 211 211 { 212 212 ASSERT(m_element); 213 ASSERT(m_element-> attributeData());213 ASSERT(m_element->elementData()); 214 214 return *m_element->getAttributeItem(qualifiedName()); 215 215 } -
trunk/Source/WebCore/dom/DocumentSharedObjectPool.cpp
r142698 r142791 1 1 /* 2 * Copyright (C) 2012 Apple Inc. All Rights Reserved.2 * Copyright (C) 2012, 2013 Apple Inc. All Rights Reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 32 32 namespace WebCore { 33 33 34 class ImmutableElementAttributeDataCacheKey {34 class ShareableElementDataCacheKey { 35 35 public: 36 ImmutableElementAttributeDataCacheKey(const Attribute* attributes, unsigned attributeCount)36 ShareableElementDataCacheKey(const Attribute* attributes, unsigned attributeCount) 37 37 : m_attributes(attributes) 38 38 , m_attributeCount(attributeCount) 39 39 { } 40 40 41 bool operator!=(const ImmutableElementAttributeDataCacheKey& other) const41 bool operator!=(const ShareableElementDataCacheKey& other) const 42 42 { 43 43 if (m_attributeCount != other.m_attributeCount) … … 56 56 }; 57 57 58 class ImmutableElementAttributeDataCacheEntry {58 class ShareableElementDataCacheEntry { 59 59 public: 60 ImmutableElementAttributeDataCacheEntry(const ImmutableElementAttributeDataCacheKey& k, PassRefPtr<ElementAttributeData> v)60 ShareableElementDataCacheEntry(const ShareableElementDataCacheKey& k, PassRefPtr<ElementData> v) 61 61 : key(k) 62 62 , value(v) 63 63 { } 64 64 65 ImmutableElementAttributeDataCacheKey key;66 RefPtr<Element AttributeData> value;65 ShareableElementDataCacheKey key; 66 RefPtr<ElementData> value; 67 67 }; 68 68 69 PassRefPtr<Element AttributeData> DocumentSharedObjectPool::cachedImmutableElementAttributeData(const Vector<Attribute>& attributes)69 PassRefPtr<ElementData> DocumentSharedObjectPool::cachedShareableElementDataWithAttributes(const Vector<Attribute>& attributes) 70 70 { 71 71 ASSERT(!attributes.isEmpty()); 72 72 73 ImmutableElementAttributeDataCacheKey cacheKey(attributes.data(), attributes.size());73 ShareableElementDataCacheKey cacheKey(attributes.data(), attributes.size()); 74 74 unsigned cacheHash = cacheKey.hash(); 75 75 76 ImmutableElementAttributeDataCache::iterator cacheIterator = m_immutableElementAttributeDataCache.add(cacheHash, nullptr).iterator;76 ShareableElementDataCache::iterator cacheIterator = m_shareableElementDataCache.add(cacheHash, nullptr).iterator; 77 77 if (cacheIterator->value && cacheIterator->value->key != cacheKey) 78 78 cacheHash = 0; 79 79 80 RefPtr<Element AttributeData> attributeData;80 RefPtr<ElementData> elementData; 81 81 if (cacheHash && cacheIterator->value) 82 attributeData = cacheIterator->value->value;82 elementData = cacheIterator->value->value; 83 83 else 84 attributeData = ElementAttributeData::createImmutable(attributes);84 elementData = ElementData::createShareableWithAttributes(attributes); 85 85 86 86 if (!cacheHash || cacheIterator->value) 87 return attributeData.release();87 return elementData.release(); 88 88 89 cacheIterator->value = adoptPtr(new ImmutableElementAttributeDataCacheEntry(ImmutableElementAttributeDataCacheKey(attributeData->immutableAttributeArray(), attributeData->length()), attributeData));89 cacheIterator->value = adoptPtr(new ShareableElementDataCacheEntry(ShareableElementDataCacheKey(elementData->immutableAttributeArray(), elementData->length()), elementData)); 90 90 91 return attributeData.release();91 return elementData.release(); 92 92 } 93 93 -
trunk/Source/WebCore/dom/DocumentSharedObjectPool.h
r136334 r142791 1 1 /* 2 * Copyright (C) 2012 Apple Inc. All Rights Reserved.2 * Copyright (C) 2012, 2013 Apple Inc. All Rights Reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 35 35 36 36 class Attribute; 37 class Element AttributeData;38 class ImmutableElementAttributeDataCacheEntry;37 class ElementData; 38 class ShareableElementDataCacheEntry; 39 39 40 40 class DocumentSharedObjectPool { … … 43 43 ~DocumentSharedObjectPool(); 44 44 45 PassRefPtr<Element AttributeData> cachedImmutableElementAttributeData(const Vector<Attribute>&);45 PassRefPtr<ElementData> cachedShareableElementDataWithAttributes(const Vector<Attribute>&); 46 46 47 47 private: 48 48 DocumentSharedObjectPool(); 49 49 50 typedef HashMap<unsigned, OwnPtr< ImmutableElementAttributeDataCacheEntry>, AlreadyHashed> ImmutableElementAttributeDataCache;51 ImmutableElementAttributeDataCache m_immutableElementAttributeDataCache;50 typedef HashMap<unsigned, OwnPtr<ShareableElementDataCacheEntry>, AlreadyHashed> ShareableElementDataCache; 51 ShareableElementDataCache m_shareableElementDataCache; 52 52 }; 53 53 -
trunk/Source/WebCore/dom/Element.cpp
r142714 r142791 277 277 PassRefPtr<Attr> Element::detachAttribute(size_t index) 278 278 { 279 ASSERT( attributeData());280 281 const Attribute* attribute = attributeData()->attributeItem(index);279 ASSERT(elementData()); 280 281 const Attribute* attribute = elementData()->attributeItem(index); 282 282 ASSERT(attribute); 283 283 … … 294 294 void Element::removeAttribute(const QualifiedName& name) 295 295 { 296 if (! attributeData())296 if (!elementData()) 297 297 return; 298 298 299 size_t index = attributeData()->getAttributeItemIndex(name);299 size_t index = elementData()->getAttributeItemIndex(name); 300 300 if (index == notFound) 301 301 return; … … 314 314 NamedNodeMap* Element::attributes() const 315 315 { 316 ensure UpdatedAttributeData();316 ensureElementDataWithSynchronizedAttributes(); 317 317 ElementRareData* rareData = const_cast<Element*>(this)->ensureElementRareData(); 318 318 if (NamedNodeMap* attributeMap = rareData->attributeMap()) … … 335 335 const AtomicString& Element::getAttribute(const QualifiedName& name) const 336 336 { 337 if (! attributeData())337 if (!elementData()) 338 338 return nullAtom; 339 339 340 if (UNLIKELY(name == styleAttr && attributeData()->m_styleAttributeIsDirty))340 if (UNLIKELY(name == styleAttr && elementData()->m_styleAttributeIsDirty)) 341 341 updateStyleAttribute(); 342 342 343 343 #if ENABLE(SVG) 344 if (UNLIKELY( attributeData()->m_animatedSVGAttributesAreDirty))344 if (UNLIKELY(elementData()->m_animatedSVGAttributesAreDirty)) 345 345 updateAnimatedSVGAttribute(name); 346 346 #endif … … 707 707 const AtomicString& Element::getAttribute(const AtomicString& name) const 708 708 { 709 if (! attributeData())709 if (!elementData()) 710 710 return nullAtom; 711 711 … … 713 713 714 714 // Update the 'style' attribute if it's invalid and being requested: 715 if ( attributeData()->m_styleAttributeIsDirty && equalPossiblyIgnoringCase(name, styleAttr.localName(), ignoreCase))715 if (elementData()->m_styleAttributeIsDirty && equalPossiblyIgnoringCase(name, styleAttr.localName(), ignoreCase)) 716 716 updateStyleAttribute(); 717 717 718 718 #if ENABLE(SVG) 719 if ( attributeData()->m_animatedSVGAttributesAreDirty) {719 if (elementData()->m_animatedSVGAttributesAreDirty) { 720 720 // We're not passing a namespace argument on purpose. SVGNames::*Attr are defined w/o namespaces as well. 721 721 updateAnimatedSVGAttribute(QualifiedName(nullAtom, name, nullAtom)); … … 723 723 #endif 724 724 725 if (const Attribute* attribute = attributeData()->getAttributeItem(name, ignoreCase))725 if (const Attribute* attribute = elementData()->getAttributeItem(name, ignoreCase)) 726 726 return attribute->value(); 727 727 return nullAtom; … … 742 742 const AtomicString& localName = shouldIgnoreAttributeCase(this) ? name.lower() : name; 743 743 744 size_t index = ensure UpdatedAttributeData()->getAttributeItemIndex(localName, false);744 size_t index = ensureElementDataWithSynchronizedAttributes()->getAttributeItemIndex(localName, false); 745 745 const QualifiedName& qName = index != notFound ? attributeItem(index)->name() : QualifiedName(nullAtom, localName, nullAtom); 746 746 setAttributeInternal(index, qName, value, NotInSynchronizationOfLazyAttribute); … … 749 749 void Element::setAttribute(const QualifiedName& name, const AtomicString& value) 750 750 { 751 setAttributeInternal(ensure UpdatedAttributeData()->getAttributeItemIndex(name), name, value, NotInSynchronizationOfLazyAttribute);751 setAttributeInternal(ensureElementDataWithSynchronizedAttributes()->getAttributeItemIndex(name), name, value, NotInSynchronizationOfLazyAttribute); 752 752 } 753 753 754 754 void Element::setSynchronizedLazyAttribute(const QualifiedName& name, const AtomicString& value) 755 755 { 756 setAttributeInternal( mutableAttributeData()->getAttributeItemIndex(name), name, value, InSynchronizationOfLazyAttribute);756 setAttributeInternal(ensureUniqueElementData()->getAttributeItemIndex(name), name, value, InSynchronizationOfLazyAttribute); 757 757 } 758 758 … … 775 775 if (newValue != attributeItem(index)->value()) { 776 776 // If there is an Attr node hooked to this attribute, the Attr::setValue() call below 777 // will write into the Element AttributeData.777 // will write into the ElementData. 778 778 // FIXME: Refactor this so it makes some sense. 779 779 if (RefPtr<Attr> attrNode = inSynchronizationOfLazyAttribute ? 0 : attrIfExists(name)) 780 780 attrNode->setValue(newValue); 781 781 else 782 mutableAttributeData()->attributeItem(index)->setValue(newValue);782 ensureUniqueElementData()->attributeItem(index)->setValue(newValue); 783 783 } 784 784 … … 820 820 821 821 if (isIdAttributeName(name)) { 822 AtomicString oldId = attributeData()->idForStyleResolution();822 AtomicString oldId = elementData()->idForStyleResolution(); 823 823 AtomicString newId = makeIdForStyleResolution(newValue, document()->inQuirksMode()); 824 824 if (newId != oldId) { 825 attributeData()->setIdForStyleResolution(newId);825 elementData()->setIdForStyleResolution(newId); 826 826 shouldInvalidateStyle = testShouldInvalidateStyle && checkNeedsStyleInvalidationForIdChange(oldId, newId, styleResolver); 827 827 } … … 923 923 if (classStringHasClassName(newClassString)) { 924 924 const bool shouldFoldCase = document()->inQuirksMode(); 925 const SpaceSplitString oldClasses = attributeData()->classNames();926 attributeData()->setClass(newClassString, shouldFoldCase);927 const SpaceSplitString& newClasses = attributeData()->classNames();925 const SpaceSplitString oldClasses = elementData()->classNames(); 926 elementData()->setClass(newClassString, shouldFoldCase); 927 const SpaceSplitString& newClasses = elementData()->classNames(); 928 928 shouldInvalidateStyle = testShouldInvalidateStyle && checkSelectorForClassChange(oldClasses, newClasses, *styleResolver); 929 929 } else { 930 const SpaceSplitString& oldClasses = attributeData()->classNames();930 const SpaceSplitString& oldClasses = elementData()->classNames(); 931 931 shouldInvalidateStyle = testShouldInvalidateStyle && checkSelectorForClassChange(oldClasses, *styleResolver); 932 attributeData()->clearClass();932 elementData()->clearClass(); 933 933 } 934 934 … … 946 946 947 947 if (isIdAttributeName(name)) { 948 AtomicString oldId = attributeData()->idForStyleResolution();948 AtomicString oldId = elementData()->idForStyleResolution(); 949 949 AtomicString newId = makeIdForStyleResolution(newValue, document()->inQuirksMode()); 950 950 if (newId != oldId) { … … 960 960 if (classStringHasClassName(newClassString)) { 961 961 const bool shouldFoldCase = document()->inQuirksMode(); 962 const SpaceSplitString& oldClasses = attributeData()->classNames();962 const SpaceSplitString& oldClasses = elementData()->classNames(); 963 963 const SpaceSplitString newClasses(newClassString, shouldFoldCase); 964 964 if (checkSelectorForClassChange(oldClasses, newClasses, featureSet)) 965 965 return true; 966 966 } else { 967 const SpaceSplitString& oldClasses = attributeData()->classNames();967 const SpaceSplitString& oldClasses = elementData()->classNames(); 968 968 if (checkSelectorForClassChange(oldClasses, featureSet)) 969 969 return true; … … 996 996 ASSERT(!parentNode()); 997 997 998 ASSERT(!m_ attributeData);998 ASSERT(!m_elementData); 999 999 1000 1000 if (attributeVector.isEmpty()) … … 1021 1021 1022 1022 if (document() && document()->sharedObjectPool()) 1023 m_ attributeData = document()->sharedObjectPool()->cachedImmutableElementAttributeData(filteredAttributes);1023 m_elementData = document()->sharedObjectPool()->cachedShareableElementDataWithAttributes(filteredAttributes); 1024 1024 else 1025 m_ attributeData = ElementAttributeData::createImmutable(filteredAttributes);1025 m_elementData = ElementData::createShareableWithAttributes(filteredAttributes); 1026 1026 1027 1027 // Iterate over the set of attributes we already have on the stack in case 1028 // attributeChanged mutates m_ attributeData.1028 // attributeChanged mutates m_elementData. 1029 1029 // FIXME: Find a way so we don't have to do this. 1030 1030 for (unsigned i = 0; i < filteredAttributes.size(); ++i) … … 1035 1035 { 1036 1036 updateInvalidAttributes(); 1037 return attributeData() && attributeData()->length();1037 return elementData() && elementData()->length(); 1038 1038 } 1039 1039 1040 1040 bool Element::hasEquivalentAttributes(const Element* other) const 1041 1041 { 1042 const Element AttributeData* attributeData = updatedAttributeData();1043 const Element AttributeData* otherAttributeData = other->updatedAttributeData();1044 if ( attributeData == otherAttributeData)1042 const ElementData* elementData = elementDataWithSynchronizedAttributes(); 1043 const ElementData* otherElementData = other->elementDataWithSynchronizedAttributes(); 1044 if (elementData == otherElementData) 1045 1045 return true; 1046 if ( attributeData)1047 return attributeData->isEquivalent(otherAttributeData);1048 if (other AttributeData)1049 return other AttributeData->isEquivalent(attributeData);1046 if (elementData) 1047 return elementData->isEquivalent(otherElementData); 1048 if (otherElementData) 1049 return otherElementData->isEquivalent(elementData); 1050 1050 return true; 1051 1051 } … … 1688 1688 1689 1689 updateInvalidAttributes(); 1690 Element AttributeData* attributeData = mutableAttributeData();1691 1692 size_t index = attributeData->getAttributeItemIndex(attrNode->qualifiedName());1690 ElementData* elementData = ensureUniqueElementData(); 1691 1692 size_t index = elementData->getAttributeItemIndex(attrNode->qualifiedName()); 1693 1693 if (index != notFound) { 1694 1694 if (oldAttrNode) 1695 detachAttrNodeFromElementWithValue(oldAttrNode.get(), attributeData->attributeItem(index)->value());1695 detachAttrNodeFromElementWithValue(oldAttrNode.get(), elementData->attributeItem(index)->value()); 1696 1696 else 1697 oldAttrNode = Attr::create(document(), attrNode->qualifiedName(), attributeData->attributeItem(index)->value());1697 oldAttrNode = Attr::create(document(), attrNode->qualifiedName(), elementData->attributeItem(index)->value()); 1698 1698 } 1699 1699 … … 1724 1724 ASSERT(document() == attr->document()); 1725 1725 1726 const Element AttributeData* attributeData = updatedAttributeData();1727 ASSERT( attributeData);1728 1729 size_t index = attributeData->getAttributeItemIndex(attr->qualifiedName());1726 const ElementData* elementData = elementDataWithSynchronizedAttributes(); 1727 ASSERT(elementData); 1728 1729 size_t index = elementData->getAttributeItemIndex(attr->qualifiedName()); 1730 1730 if (index == notFound) { 1731 1731 ec = NOT_FOUND_ERR; … … 1766 1766 ASSERT_WITH_SECURITY_IMPLICATION(index < attributeCount()); 1767 1767 1768 Element AttributeData* attributeData = mutableAttributeData();1769 1770 QualifiedName name = attributeData->attributeItem(index)->name();1771 AtomicString valueBeingRemoved = attributeData->attributeItem(index)->value();1768 ElementData* elementData = ensureUniqueElementData(); 1769 1770 QualifiedName name = elementData->attributeItem(index)->name(); 1771 AtomicString valueBeingRemoved = elementData->attributeItem(index)->value(); 1772 1772 1773 1773 if (!inSynchronizationOfLazyAttribute) { … … 1777 1777 1778 1778 if (RefPtr<Attr> attrNode = attrIfExists(name)) 1779 detachAttrNodeFromElementWithValue(attrNode.get(), attributeData->attributeItem(index)->value());1780 1781 attributeData->removeAttribute(index);1779 detachAttrNodeFromElementWithValue(attrNode.get(), elementData->attributeItem(index)->value()); 1780 1781 elementData->removeAttribute(index); 1782 1782 1783 1783 if (!inSynchronizationOfLazyAttribute) … … 1789 1789 if (!inSynchronizationOfLazyAttribute) 1790 1790 willModifyAttribute(name, nullAtom, value); 1791 mutableAttributeData()->addAttribute(Attribute(name, value));1791 ensureUniqueElementData()->addAttribute(Attribute(name, value)); 1792 1792 if (!inSynchronizationOfLazyAttribute) 1793 1793 didAddAttribute(name, value); … … 1796 1796 void Element::removeAttribute(const AtomicString& name) 1797 1797 { 1798 if (! attributeData())1798 if (!elementData()) 1799 1799 return; 1800 1800 1801 1801 AtomicString localName = shouldIgnoreAttributeCase(this) ? name.lower() : name; 1802 size_t index = attributeData()->getAttributeItemIndex(localName, false);1802 size_t index = elementData()->getAttributeItemIndex(localName, false); 1803 1803 if (index == notFound) { 1804 if (UNLIKELY(localName == styleAttr) && attributeData()->m_styleAttributeIsDirty && isStyledElement())1804 if (UNLIKELY(localName == styleAttr) && elementData()->m_styleAttributeIsDirty && isStyledElement()) 1805 1805 static_cast<StyledElement*>(this)->removeAllInlineStyleProperties(); 1806 1806 return; … … 1817 1817 PassRefPtr<Attr> Element::getAttributeNode(const AtomicString& name) 1818 1818 { 1819 const Element AttributeData* attributeData = updatedAttributeData();1820 if (! attributeData)1819 const ElementData* elementData = elementDataWithSynchronizedAttributes(); 1820 if (!elementData) 1821 1821 return 0; 1822 const Attribute* attribute = attributeData->getAttributeItem(name, shouldIgnoreAttributeCase(this));1822 const Attribute* attribute = elementData->getAttributeItem(name, shouldIgnoreAttributeCase(this)); 1823 1823 if (!attribute) 1824 1824 return 0; … … 1828 1828 PassRefPtr<Attr> Element::getAttributeNodeNS(const AtomicString& namespaceURI, const AtomicString& localName) 1829 1829 { 1830 const Element AttributeData* attributeData = updatedAttributeData();1831 if (! attributeData)1830 const ElementData* elementData = elementDataWithSynchronizedAttributes(); 1831 if (!elementData) 1832 1832 return 0; 1833 const Attribute* attribute = attributeData->getAttributeItem(QualifiedName(nullAtom, localName, namespaceURI));1833 const Attribute* attribute = elementData->getAttributeItem(QualifiedName(nullAtom, localName, namespaceURI)); 1834 1834 if (!attribute) 1835 1835 return 0; … … 1839 1839 bool Element::hasAttribute(const AtomicString& name) const 1840 1840 { 1841 if (! attributeData())1841 if (!elementData()) 1842 1842 return false; 1843 1843 … … 1845 1845 // there may be a way to remove it. 1846 1846 AtomicString localName = shouldIgnoreAttributeCase(this) ? name.lower() : name; 1847 return updatedAttributeData()->getAttributeItem(localName, false);1847 return elementDataWithSynchronizedAttributes()->getAttributeItem(localName, false); 1848 1848 } 1849 1849 1850 1850 bool Element::hasAttributeNS(const AtomicString& namespaceURI, const AtomicString& localName) const 1851 1851 { 1852 const Element AttributeData* attributeData = updatedAttributeData();1853 if (! attributeData)1852 const ElementData* elementData = elementDataWithSynchronizedAttributes(); 1853 if (!elementData) 1854 1854 return false; 1855 return attributeData->getAttributeItem(QualifiedName(nullAtom, localName, namespaceURI));1855 return elementData->getAttributeItem(QualifiedName(nullAtom, localName, namespaceURI)); 1856 1856 } 1857 1857 … … 2160 2160 do { 2161 2161 if (n->isElementNode()) { 2162 if (const Element AttributeData* attributeData = static_cast<const Element*>(n)->attributeData()) {2162 if (const ElementData* elementData = static_cast<const Element*>(n)->elementData()) { 2163 2163 // Spec: xml:lang takes precedence -- http://www.w3.org/TR/xhtml1/#C_7 2164 if (const Attribute* attribute = attributeData->getAttributeItem(XMLNames::langAttr))2164 if (const Attribute* attribute = elementData->getAttributeItem(XMLNames::langAttr)) 2165 2165 value = attribute->value(); 2166 else if (const Attribute* attribute = attributeData->getAttributeItem(HTMLNames::langAttr))2166 else if (const Attribute* attribute = elementData->getAttributeItem(HTMLNames::langAttr)) 2167 2167 value = attribute->value(); 2168 2168 } … … 2328 2328 { 2329 2329 #if !ASSERT_DISABLED 2330 if ( attributeData()) {2330 if (elementData()) { 2331 2331 if (const Attribute* attribute = getAttributeItem(name)) 2332 2332 ASSERT(isURLAttribute(*attribute)); … … 2339 2339 { 2340 2340 #if !ASSERT_DISABLED 2341 if ( attributeData()) {2341 if (elementData()) { 2342 2342 if (const Attribute* attribute = getAttributeItem(name)) 2343 2343 ASSERT(isURLAttribute(*attribute)); … … 2746 2746 2747 2747 other.updateInvalidAttributes(); 2748 if (!other.m_ attributeData) {2749 m_ attributeData.clear();2748 if (!other.m_elementData) { 2749 m_elementData.clear(); 2750 2750 return; 2751 2751 } … … 2763 2763 updateName(oldName, newName); 2764 2764 2765 // If 'other' has a mutable Element AttributeData, convert it to an immutable one so we can share it between both elements.2765 // If 'other' has a mutable ElementData, convert it to an immutable one so we can share it between both elements. 2766 2766 // We can only do this if there is no CSSOM wrapper for other's inline style, and there are no presentation attributes. 2767 if (other.m_ attributeData->isMutable()2768 && !other.m_ attributeData->presentationAttributeStyle()2769 && (!other.m_ attributeData->inlineStyle() || !other.m_attributeData->inlineStyle()->hasCSSOMWrapper()))2770 const_cast<Element&>(other).m_ attributeData = other.m_attributeData->makeImmutableCopy();2771 2772 if (!other.m_ attributeData->isMutable())2773 m_ attributeData = other.m_attributeData;2767 if (other.m_elementData->isUnique() 2768 && !other.m_elementData->presentationAttributeStyle() 2769 && (!other.m_elementData->inlineStyle() || !other.m_elementData->inlineStyle()->hasCSSOMWrapper())) 2770 const_cast<Element&>(other).m_elementData = other.m_elementData->makeShareableCopy(); 2771 2772 if (!other.m_elementData->isUnique()) 2773 m_elementData = other.m_elementData; 2774 2774 else 2775 m_ attributeData = other.m_attributeData->makeMutableCopy();2776 2777 for (unsigned i = 0; i < m_ attributeData->length(); ++i) {2778 const Attribute* attribute = const_cast<const Element AttributeData*>(m_attributeData.get())->attributeItem(i);2775 m_elementData = other.m_elementData->makeUniqueCopy(); 2776 2777 for (unsigned i = 0; i < m_elementData->length(); ++i) { 2778 const Attribute* attribute = const_cast<const ElementData*>(m_elementData.get())->attributeItem(i); 2779 2779 attributeChanged(attribute->name(), attribute->value()); 2780 2780 } … … 2787 2787 } 2788 2788 2789 void Element::create MutableAttributeData()2790 { 2791 if (!m_ attributeData)2792 m_ attributeData = ElementAttributeData::create();2789 void Element::createUniqueElementData() 2790 { 2791 if (!m_elementData) 2792 m_elementData = ElementData::createUnique(); 2793 2793 else 2794 m_ attributeData = m_attributeData->makeMutableCopy();2794 m_elementData = m_elementData->makeUniqueCopy(); 2795 2795 } 2796 2796 … … 2800 2800 ContainerNode::reportMemoryUsage(memoryObjectInfo); 2801 2801 info.addMember(m_tagName, "tagName"); 2802 info.addMember(m_ attributeData, "attributeData");2802 info.addMember(m_elementData, "elementData"); 2803 2803 } 2804 2804 … … 2820 2820 #endif 2821 2821 2822 void Element AttributeData::deref()2822 void ElementData::deref() 2823 2823 { 2824 2824 if (!derefBase()) 2825 2825 return; 2826 2826 2827 if (m_is Mutable)2828 delete static_cast< MutableElementAttributeData*>(this);2827 if (m_isUnique) 2828 delete static_cast<UniqueElementData*>(this); 2829 2829 else 2830 delete static_cast< ImmutableElementAttributeData*>(this);2831 } 2832 2833 Element AttributeData::ElementAttributeData()2834 : m_is Mutable(true)2830 delete static_cast<ShareableElementData*>(this); 2831 } 2832 2833 ElementData::ElementData() 2834 : m_isUnique(true) 2835 2835 , m_arraySize(0) 2836 2836 , m_presentationAttributeStyleIsDirty(false) … … 2842 2842 } 2843 2843 2844 Element AttributeData::ElementAttributeData(unsigned arraySize)2845 : m_is Mutable(false)2844 ElementData::ElementData(unsigned arraySize) 2845 : m_isUnique(false) 2846 2846 , m_arraySize(arraySize) 2847 2847 , m_presentationAttributeStyleIsDirty(false) … … 2853 2853 } 2854 2854 2855 struct SameSizeAsElement AttributeData : public RefCounted<SameSizeAsElementAttributeData> {2855 struct SameSizeAsElementData : public RefCounted<SameSizeAsElementData> { 2856 2856 unsigned bitfield; 2857 2857 void* refPtrs[3]; 2858 2858 }; 2859 2859 2860 COMPILE_ASSERT(sizeof(Element AttributeData) == sizeof(SameSizeAsElementAttributeData), element_attribute_data_should_stay_small);2861 2862 static size_t sizeFor ImmutableElementAttributeDataWithAttributeCount(unsigned count)2863 { 2864 return sizeof( ImmutableElementAttributeData) - sizeof(void*) + sizeof(Attribute) * count;2865 } 2866 2867 PassRefPtr<Element AttributeData> ElementAttributeData::createImmutable(const Vector<Attribute>& attributes)2868 { 2869 void* slot = WTF::fastMalloc(sizeFor ImmutableElementAttributeDataWithAttributeCount(attributes.size()));2870 return adoptRef(new (slot) ImmutableElementAttributeData(attributes));2871 } 2872 2873 PassRefPtr<Element AttributeData> ElementAttributeData::create()2874 { 2875 return adoptRef(new MutableElementAttributeData);2876 } 2877 2878 ImmutableElementAttributeData::ImmutableElementAttributeData(const Vector<Attribute>& attributes)2879 : Element AttributeData(attributes.size())2860 COMPILE_ASSERT(sizeof(ElementData) == sizeof(SameSizeAsElementData), element_attribute_data_should_stay_small); 2861 2862 static size_t sizeForShareableElementDataWithAttributeCount(unsigned count) 2863 { 2864 return sizeof(ShareableElementData) - sizeof(void*) + sizeof(Attribute) * count; 2865 } 2866 2867 PassRefPtr<ElementData> ElementData::createShareableWithAttributes(const Vector<Attribute>& attributes) 2868 { 2869 void* slot = WTF::fastMalloc(sizeForShareableElementDataWithAttributeCount(attributes.size())); 2870 return adoptRef(new (slot) ShareableElementData(attributes)); 2871 } 2872 2873 PassRefPtr<ElementData> ElementData::createUnique() 2874 { 2875 return adoptRef(new UniqueElementData); 2876 } 2877 2878 ShareableElementData::ShareableElementData(const Vector<Attribute>& attributes) 2879 : ElementData(attributes.size()) 2880 2880 { 2881 2881 for (unsigned i = 0; i < m_arraySize; ++i) … … 2883 2883 } 2884 2884 2885 ImmutableElementAttributeData::~ImmutableElementAttributeData()2885 ShareableElementData::~ShareableElementData() 2886 2886 { 2887 2887 for (unsigned i = 0; i < m_arraySize; ++i) … … 2889 2889 } 2890 2890 2891 ImmutableElementAttributeData::ImmutableElementAttributeData(const MutableElementAttributeData& other)2892 : Element AttributeData(other, false)2891 ShareableElementData::ShareableElementData(const UniqueElementData& other) 2892 : ElementData(other, false) 2893 2893 { 2894 2894 ASSERT(!other.m_presentationAttributeStyle); … … 2903 2903 } 2904 2904 2905 Element AttributeData::ElementAttributeData(const ElementAttributeData& other, bool isMutable)2906 : m_is Mutable(isMutable)2907 , m_arraySize(is Mutable ? 0 : other.length())2905 ElementData::ElementData(const ElementData& other, bool isUnique) 2906 : m_isUnique(isUnique) 2907 , m_arraySize(isUnique ? 0 : other.length()) 2908 2908 , m_presentationAttributeStyleIsDirty(other.m_presentationAttributeStyleIsDirty) 2909 2909 , m_styleAttributeIsDirty(other.m_styleAttributeIsDirty) … … 2917 2917 } 2918 2918 2919 MutableElementAttributeData::MutableElementAttributeData()2920 { 2921 } 2922 2923 MutableElementAttributeData::MutableElementAttributeData(const MutableElementAttributeData& other)2924 : Element AttributeData(other, true)2919 UniqueElementData::UniqueElementData() 2920 { 2921 } 2922 2923 UniqueElementData::UniqueElementData(const UniqueElementData& other) 2924 : ElementData(other, true) 2925 2925 , m_presentationAttributeStyle(other.m_presentationAttributeStyle) 2926 2926 , m_attributeVector(other.m_attributeVector) … … 2929 2929 } 2930 2930 2931 MutableElementAttributeData::MutableElementAttributeData(const ImmutableElementAttributeData& other)2932 : Element AttributeData(other, true)2933 { 2934 // An ImmutableElementAttributeData should never have a mutable inline StylePropertySet attached.2931 UniqueElementData::UniqueElementData(const ShareableElementData& other) 2932 : ElementData(other, true) 2933 { 2934 // An ShareableElementData should never have a mutable inline StylePropertySet attached. 2935 2935 ASSERT(!other.m_inlineStyle || !other.m_inlineStyle->isMutable()); 2936 2936 m_inlineStyle = other.m_inlineStyle; … … 2941 2941 } 2942 2942 2943 PassRefPtr<Element AttributeData> ElementAttributeData::makeMutableCopy() const2944 { 2945 if (is Mutable())2946 return adoptRef(new MutableElementAttributeData(static_cast<const MutableElementAttributeData&>(*this)));2947 return adoptRef(new MutableElementAttributeData(static_cast<const ImmutableElementAttributeData&>(*this)));2948 } 2949 2950 PassRefPtr<Element AttributeData> ElementAttributeData::makeImmutableCopy() const2951 { 2952 ASSERT(is Mutable());2953 void* slot = WTF::fastMalloc(sizeFor ImmutableElementAttributeDataWithAttributeCount(mutableAttributeVector().size()));2954 return adoptRef(new (slot) ImmutableElementAttributeData(static_cast<const MutableElementAttributeData&>(*this)));2955 } 2956 2957 void Element AttributeData::setPresentationAttributeStyle(PassRefPtr<StylePropertySet> style) const2958 { 2959 ASSERT(m_is Mutable);2960 static_cast<const MutableElementAttributeData*>(this)->m_presentationAttributeStyle = style;2961 } 2962 2963 void Element AttributeData::addAttribute(const Attribute& attribute)2964 { 2965 ASSERT(is Mutable());2943 PassRefPtr<ElementData> ElementData::makeUniqueCopy() const 2944 { 2945 if (isUnique()) 2946 return adoptRef(new UniqueElementData(static_cast<const UniqueElementData&>(*this))); 2947 return adoptRef(new UniqueElementData(static_cast<const ShareableElementData&>(*this))); 2948 } 2949 2950 PassRefPtr<ElementData> ElementData::makeShareableCopy() const 2951 { 2952 ASSERT(isUnique()); 2953 void* slot = WTF::fastMalloc(sizeForShareableElementDataWithAttributeCount(mutableAttributeVector().size())); 2954 return adoptRef(new (slot) ShareableElementData(static_cast<const UniqueElementData&>(*this))); 2955 } 2956 2957 void ElementData::setPresentationAttributeStyle(PassRefPtr<StylePropertySet> style) const 2958 { 2959 ASSERT(m_isUnique); 2960 static_cast<const UniqueElementData*>(this)->m_presentationAttributeStyle = style; 2961 } 2962 2963 void ElementData::addAttribute(const Attribute& attribute) 2964 { 2965 ASSERT(isUnique()); 2966 2966 mutableAttributeVector().append(attribute); 2967 2967 } 2968 2968 2969 void Element AttributeData::removeAttribute(size_t index)2970 { 2971 ASSERT(is Mutable());2969 void ElementData::removeAttribute(size_t index) 2970 { 2971 ASSERT(isUnique()); 2972 2972 ASSERT_WITH_SECURITY_IMPLICATION(index < length()); 2973 2973 mutableAttributeVector().remove(index); 2974 2974 } 2975 2975 2976 bool Element AttributeData::isEquivalent(const ElementAttributeData* other) const2976 bool ElementData::isEquivalent(const ElementData* other) const 2977 2977 { 2978 2978 if (!other) … … 2993 2993 } 2994 2994 2995 void Element AttributeData::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const2996 { 2997 size_t actualSize = m_is Mutable ? sizeof(ElementAttributeData) : sizeForImmutableElementAttributeDataWithAttributeCount(m_arraySize);2995 void ElementData::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const 2996 { 2997 size_t actualSize = m_isUnique ? sizeof(ElementData) : sizeForShareableElementDataWithAttributeCount(m_arraySize); 2998 2998 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM, actualSize); 2999 2999 info.addMember(m_inlineStyle, "inlineStyle"); 3000 3000 info.addMember(m_classNames, "classNames"); 3001 3001 info.addMember(m_idForStyleResolution, "idForStyleResolution"); 3002 if (m_is Mutable) {3002 if (m_isUnique) { 3003 3003 info.addMember(presentationAttributeStyle(), "presentationAttributeStyle()"); 3004 3004 info.addMember(mutableAttributeVector(), "mutableAttributeVector"); … … 3008 3008 } 3009 3009 3010 size_t Element AttributeData::getAttributeItemIndexSlowCase(const AtomicString& name, bool shouldIgnoreAttributeCase) const3010 size_t ElementData::getAttributeItemIndexSlowCase(const AtomicString& name, bool shouldIgnoreAttributeCase) const 3011 3011 { 3012 3012 // Continue to checking case-insensitively and/or full namespaced names if necessary: -
trunk/Source/WebCore/dom/Element.h
r142714 r142791 44 44 class ElementRareData; 45 45 class ElementShadow; 46 class ImmutableElementAttributeData;46 class ShareableElementData; 47 47 class IntSize; 48 48 class Locale; 49 class MutableElementAttributeData;49 class UniqueElementData; 50 50 class PseudoElement; 51 51 class RenderRegion; … … 53 53 class StylePropertySet; 54 54 55 class Element AttributeData : public RefCounted<ElementAttributeData> {55 class ElementData : public RefCounted<ElementData> { 56 56 WTF_MAKE_FAST_ALLOCATED; 57 57 public: 58 static PassRefPtr<Element AttributeData> create();59 static PassRefPtr<Element AttributeData> createImmutable(const Vector<Attribute>&);58 static PassRefPtr<ElementData> createUnique(); 59 static PassRefPtr<ElementData> createShareableWithAttributes(const Vector<Attribute>&); 60 60 61 61 // Override RefCounted's deref() to ensure operator delete is called on … … 92 92 bool hasClass() const { return !m_classNames.isNull(); } 93 93 94 bool isEquivalent(const Element AttributeData* other) const;94 bool isEquivalent(const ElementData* other) const; 95 95 96 96 void reportMemoryUsage(MemoryObjectInfo*) const; 97 97 98 bool is Mutable() const { return m_isMutable; }98 bool isUnique() const { return m_isUnique; } 99 99 const Attribute* immutableAttributeArray() const; 100 100 101 101 protected: 102 Element AttributeData();103 Element AttributeData(unsigned arraySize);104 Element AttributeData(const ElementAttributeData&, bool isMutable);105 106 unsigned m_is Mutable : 1;102 ElementData(); 103 ElementData(unsigned arraySize); 104 ElementData(const ElementData&, bool isUnique); 105 106 unsigned m_isUnique : 1; 107 107 unsigned m_arraySize : 28; 108 108 mutable unsigned m_presentationAttributeStyleIsDirty : 1; … … 119 119 friend class Element; 120 120 friend class StyledElement; 121 friend class ImmutableElementAttributeData;122 friend class MutableElementAttributeData;121 friend class ShareableElementData; 122 friend class UniqueElementData; 123 123 #if ENABLE(SVG) 124 124 friend class SVGElement; … … 129 129 size_t getAttributeItemIndexSlowCase(const AtomicString& name, bool shouldIgnoreAttributeCase) const; 130 130 131 PassRefPtr<Element AttributeData> makeMutableCopy() const;132 PassRefPtr<Element AttributeData> makeImmutableCopy() const;131 PassRefPtr<ElementData> makeUniqueCopy() const; 132 PassRefPtr<ElementData> makeShareableCopy() const; 133 133 134 134 Vector<Attribute, 4>& mutableAttributeVector(); … … 136 136 }; 137 137 138 class ImmutableElementAttributeData : public ElementAttributeData {138 class ShareableElementData : public ElementData { 139 139 public: 140 ImmutableElementAttributeData(const Vector<Attribute>&);141 ImmutableElementAttributeData(const MutableElementAttributeData&);142 ~ ImmutableElementAttributeData();140 ShareableElementData(const Vector<Attribute>&); 141 ShareableElementData(const UniqueElementData&); 142 ~ShareableElementData(); 143 143 144 144 void* m_attributeArray; 145 145 }; 146 146 147 class MutableElementAttributeData : public ElementAttributeData {147 class UniqueElementData : public ElementData { 148 148 public: 149 MutableElementAttributeData();150 MutableElementAttributeData(const ImmutableElementAttributeData&);151 MutableElementAttributeData(const MutableElementAttributeData&);149 UniqueElementData(); 150 UniqueElementData(const ShareableElementData&); 151 UniqueElementData(const UniqueElementData&); 152 152 153 153 mutable RefPtr<StylePropertySet> m_presentationAttributeStyle; … … 287 287 const Attribute* getAttributeItem(const QualifiedName&) const; 288 288 Attribute* getAttributeItem(const QualifiedName&); 289 size_t getAttributeItemIndex(const QualifiedName& name) const { return attributeData()->getAttributeItemIndex(name); }290 size_t getAttributeItemIndex(const AtomicString& name, bool shouldIgnoreAttributeCase) const { return attributeData()->getAttributeItemIndex(name, shouldIgnoreAttributeCase); }289 size_t getAttributeItemIndex(const QualifiedName& name) const { return elementData()->getAttributeItemIndex(name); } 290 size_t getAttributeItemIndex(const AtomicString& name, bool shouldIgnoreAttributeCase) const { return elementData()->getAttributeItemIndex(name, shouldIgnoreAttributeCase); } 291 291 292 292 void scrollIntoView(bool alignToTop = true); … … 372 372 void parserSetAttributes(const Vector<Attribute>&, FragmentScriptingPermission); 373 373 374 const Element AttributeData* attributeData() const { return m_attributeData.get(); }375 Element AttributeData* mutableAttributeData();376 const Element AttributeData* updatedAttributeData() const;377 const Element AttributeData* ensureUpdatedAttributeData() const;374 const ElementData* elementData() const { return m_elementData.get(); } 375 ElementData* ensureUniqueElementData(); 376 const ElementData* elementDataWithSynchronizedAttributes() const; 377 const ElementData* ensureElementDataWithSynchronizedAttributes() const; 378 378 379 379 // Clones attributes only. … … 706 706 void unregisterNamedFlowContentNode(); 707 707 708 void create MutableAttributeData();708 void createUniqueElementData(); 709 709 710 710 bool shouldInvalidateDistributionWhenAttributeChanged(ElementShadow*, const QualifiedName&, const AtomicString&); … … 718 718 void createRendererIfNeeded(); 719 719 720 RefPtr<Element AttributeData> m_attributeData;720 RefPtr<ElementData> m_elementData; 721 721 }; 722 722 … … 778 778 } 779 779 780 inline const Element AttributeData* Element::updatedAttributeData() const780 inline const ElementData* Element::elementDataWithSynchronizedAttributes() const 781 781 { 782 782 updateInvalidAttributes(); 783 return attributeData();784 } 785 786 inline const Element AttributeData* Element::ensureUpdatedAttributeData() const783 return elementData(); 784 } 785 786 inline const ElementData* Element::ensureElementDataWithSynchronizedAttributes() const 787 787 { 788 788 updateInvalidAttributes(); 789 if ( attributeData())790 return attributeData();791 return const_cast<Element*>(this)-> mutableAttributeData();789 if (elementData()) 790 return elementData(); 791 return const_cast<Element*>(this)->ensureUniqueElementData(); 792 792 } 793 793 … … 832 832 { 833 833 ASSERT(fastAttributeLookupAllowed(name)); 834 return attributeData() && getAttributeItem(name);834 return elementData() && getAttributeItem(name); 835 835 } 836 836 … … 838 838 { 839 839 ASSERT(fastAttributeLookupAllowed(name)); 840 if ( attributeData()) {840 if (elementData()) { 841 841 if (const Attribute* attribute = getAttributeItem(name)) 842 842 return attribute->value(); … … 847 847 inline bool Element::hasAttributesWithoutUpdate() const 848 848 { 849 return attributeData() && !attributeData()->isEmpty();849 return elementData() && !elementData()->isEmpty(); 850 850 } 851 851 … … 853 853 { 854 854 ASSERT(hasID()); 855 return attributeData()->idForStyleResolution();855 return elementData()->idForStyleResolution(); 856 856 } 857 857 … … 883 883 { 884 884 ASSERT(hasClass()); 885 ASSERT( attributeData());886 return attributeData()->classNames();885 ASSERT(elementData()); 886 return elementData()->classNames(); 887 887 } 888 888 889 889 inline size_t Element::attributeCount() const 890 890 { 891 ASSERT( attributeData());892 return attributeData()->length();891 ASSERT(elementData()); 892 return elementData()->length(); 893 893 } 894 894 895 895 inline const Attribute* Element::attributeItem(unsigned index) const 896 896 { 897 ASSERT( attributeData());898 return attributeData()->attributeItem(index);897 ASSERT(elementData()); 898 return elementData()->attributeItem(index); 899 899 } 900 900 901 901 inline const Attribute* Element::getAttributeItem(const QualifiedName& name) const 902 902 { 903 ASSERT( attributeData());904 return attributeData()->getAttributeItem(name);903 ASSERT(elementData()); 904 return elementData()->getAttributeItem(name); 905 905 } 906 906 907 907 inline Attribute* Element::getAttributeItem(const QualifiedName& name) 908 908 { 909 ASSERT( attributeData());910 return mutableAttributeData()->getAttributeItem(name);909 ASSERT(elementData()); 910 return ensureUniqueElementData()->getAttributeItem(name); 911 911 } 912 912 913 913 inline void Element::updateInvalidAttributes() const 914 914 { 915 if (! attributeData())915 if (!elementData()) 916 916 return; 917 917 918 if ( attributeData()->m_styleAttributeIsDirty)918 if (elementData()->m_styleAttributeIsDirty) 919 919 updateStyleAttribute(); 920 920 921 921 #if ENABLE(SVG) 922 if ( attributeData()->m_animatedSVGAttributesAreDirty)922 if (elementData()->m_animatedSVGAttributesAreDirty) 923 923 updateAnimatedSVGAttribute(anyQName()); 924 924 #endif … … 927 927 inline bool Element::hasID() const 928 928 { 929 return attributeData() && attributeData()->hasID();929 return elementData() && elementData()->hasID(); 930 930 } 931 931 932 932 inline bool Element::hasClass() const 933 933 { 934 return attributeData() && attributeData()->hasClass();935 } 936 937 inline Element AttributeData* Element::mutableAttributeData()938 { 939 if (! attributeData() || !attributeData()->isMutable())940 create MutableAttributeData();941 return m_ attributeData.get();934 return elementData() && elementData()->hasClass(); 935 } 936 937 inline ElementData* Element::ensureUniqueElementData() 938 { 939 if (!elementData() || !elementData()->isUnique()) 940 createUniqueElementData(); 941 return m_elementData.get(); 942 942 } 943 943 … … 976 976 return node && node->isElementNode() && toElement(node)->shadow(); 977 977 } 978 inline Vector<Attribute, 4>& Element AttributeData::mutableAttributeVector()979 { 980 ASSERT(m_is Mutable);981 return static_cast< MutableElementAttributeData*>(this)->m_attributeVector;982 } 983 984 inline const Vector<Attribute, 4>& Element AttributeData::mutableAttributeVector() const985 { 986 ASSERT(m_is Mutable);987 return static_cast<const MutableElementAttributeData*>(this)->m_attributeVector;988 } 989 990 inline const Attribute* Element AttributeData::immutableAttributeArray() const991 { 992 ASSERT(!m_is Mutable);993 return reinterpret_cast<const Attribute*>(&static_cast<const ImmutableElementAttributeData*>(this)->m_attributeArray);994 } 995 996 inline size_t Element AttributeData::length() const997 { 998 if (is Mutable())978 inline Vector<Attribute, 4>& ElementData::mutableAttributeVector() 979 { 980 ASSERT(m_isUnique); 981 return static_cast<UniqueElementData*>(this)->m_attributeVector; 982 } 983 984 inline const Vector<Attribute, 4>& ElementData::mutableAttributeVector() const 985 { 986 ASSERT(m_isUnique); 987 return static_cast<const UniqueElementData*>(this)->m_attributeVector; 988 } 989 990 inline const Attribute* ElementData::immutableAttributeArray() const 991 { 992 ASSERT(!m_isUnique); 993 return reinterpret_cast<const Attribute*>(&static_cast<const ShareableElementData*>(this)->m_attributeArray); 994 } 995 996 inline size_t ElementData::length() const 997 { 998 if (isUnique()) 999 999 return mutableAttributeVector().size(); 1000 1000 return m_arraySize; 1001 1001 } 1002 1002 1003 inline const StylePropertySet* Element AttributeData::presentationAttributeStyle() const1004 { 1005 if (!m_is Mutable)1003 inline const StylePropertySet* ElementData::presentationAttributeStyle() const 1004 { 1005 if (!m_isUnique) 1006 1006 return 0; 1007 return static_cast<const MutableElementAttributeData*>(this)->m_presentationAttributeStyle.get();1008 } 1009 1010 inline Attribute* Element AttributeData::getAttributeItem(const AtomicString& name, bool shouldIgnoreAttributeCase)1007 return static_cast<const UniqueElementData*>(this)->m_presentationAttributeStyle.get(); 1008 } 1009 1010 inline Attribute* ElementData::getAttributeItem(const AtomicString& name, bool shouldIgnoreAttributeCase) 1011 1011 { 1012 1012 size_t index = getAttributeItemIndex(name, shouldIgnoreAttributeCase); … … 1016 1016 } 1017 1017 1018 inline const Attribute* Element AttributeData::getAttributeItem(const AtomicString& name, bool shouldIgnoreAttributeCase) const1018 inline const Attribute* ElementData::getAttributeItem(const AtomicString& name, bool shouldIgnoreAttributeCase) const 1019 1019 { 1020 1020 size_t index = getAttributeItemIndex(name, shouldIgnoreAttributeCase); … … 1024 1024 } 1025 1025 1026 inline size_t Element AttributeData::getAttributeItemIndex(const QualifiedName& name) const1026 inline size_t ElementData::getAttributeItemIndex(const QualifiedName& name) const 1027 1027 { 1028 1028 for (unsigned i = 0; i < length(); ++i) { … … 1035 1035 // We use a boolean parameter instead of calling shouldIgnoreAttributeCase so that the caller 1036 1036 // can tune the behavior (hasAttribute is case sensitive whereas getAttribute is not). 1037 inline size_t Element AttributeData::getAttributeItemIndex(const AtomicString& name, bool shouldIgnoreAttributeCase) const1037 inline size_t ElementData::getAttributeItemIndex(const AtomicString& name, bool shouldIgnoreAttributeCase) const 1038 1038 { 1039 1039 unsigned len = length(); … … 1055 1055 } 1056 1056 1057 inline const Attribute* Element AttributeData::getAttributeItem(const QualifiedName& name) const1057 inline const Attribute* ElementData::getAttributeItem(const QualifiedName& name) const 1058 1058 { 1059 1059 for (unsigned i = 0; i < length(); ++i) { … … 1064 1064 } 1065 1065 1066 inline Attribute* Element AttributeData::getAttributeItem(const QualifiedName& name)1066 inline Attribute* ElementData::getAttributeItem(const QualifiedName& name) 1067 1067 { 1068 1068 for (unsigned i = 0; i < length(); ++i) { … … 1073 1073 } 1074 1074 1075 inline const Attribute* Element AttributeData::attributeItem(unsigned index) const1075 inline const Attribute* ElementData::attributeItem(unsigned index) const 1076 1076 { 1077 1077 ASSERT_WITH_SECURITY_IMPLICATION(index < length()); 1078 if (m_is Mutable)1078 if (m_isUnique) 1079 1079 return &mutableAttributeVector().at(index); 1080 1080 return &immutableAttributeArray()[index]; 1081 1081 } 1082 1082 1083 inline Attribute* Element AttributeData::attributeItem(unsigned index)1083 inline Attribute* ElementData::attributeItem(unsigned index) 1084 1084 { 1085 1085 ASSERT_WITH_SECURITY_IMPLICATION(index < length()); -
trunk/Source/WebCore/dom/Node.cpp
r142719 r142791 206 206 result.iterator->value++; 207 207 208 if (Element AttributeData* attributeData = element->attributeData()) {209 attributes += attributeData->length();208 if (ElementData* elementData = element->elementData()) { 209 attributes += elementData->length(); 210 210 ++elementsWithAttributeStorage; 211 for (unsigned i = 0; i < attributeData->length(); ++i) {212 Attribute* attr = attributeData->attributeItem(i);211 for (unsigned i = 0; i < elementData->length(); ++i) { 212 Attribute* attr = elementData->attributeItem(i); 213 213 if (attr->attr()) 214 214 ++attributesWithAttr; … … 297 297 printf(" Number of Attributes (non-Node and Node): %zu [%zu]\n", attributes, sizeof(Attribute)); 298 298 printf(" Number of Attributes with an Attr: %zu\n", attributesWithAttr); 299 printf(" Number of Elements with attribute storage: %zu [%zu]\n", elementsWithAttributeStorage, sizeof(Element AttributeData));299 printf(" Number of Elements with attribute storage: %zu [%zu]\n", elementsWithAttributeStorage, sizeof(ElementData)); 300 300 printf(" Number of Elements with RareData: %zu\n", elementsWithRareData); 301 301 printf(" Number of Elements with NamedNodeMap: %zu [%zu]\n", elementsWithNamedNodeMap, sizeof(NamedNodeMap)); … … 1754 1754 // We are comparing two attributes on the same node. Crawl our attribute map and see which one we hit first. 1755 1755 Element* owner1 = attr1->ownerElement(); 1756 owner1-> updatedAttributeData(); // Force update invalid attributes.1756 owner1->elementDataWithSynchronizedAttributes(); // Force update invalid attributes. 1757 1757 unsigned length = owner1->attributeCount(); 1758 1758 for (unsigned i = 0; i < length; ++i) { -
trunk/Source/WebCore/dom/StyledElement.cpp
r135421 r142791 129 129 void StyledElement::updateStyleAttribute() const 130 130 { 131 ASSERT( attributeData());132 ASSERT( attributeData()->m_styleAttributeIsDirty);133 attributeData()->m_styleAttributeIsDirty = false;131 ASSERT(elementData()); 132 ASSERT(elementData()->m_styleAttributeIsDirty); 133 elementData()->m_styleAttributeIsDirty = false; 134 134 if (const StylePropertySet* inlineStyle = this->inlineStyle()) 135 135 const_cast<StyledElement*>(this)->setSynchronizedLazyAttribute(styleAttr, inlineStyle->asText()); … … 149 149 StylePropertySet* StyledElement::ensureMutableInlineStyle() 150 150 { 151 RefPtr<StylePropertySet>& inlineStyle = mutableAttributeData()->m_inlineStyle;151 RefPtr<StylePropertySet>& inlineStyle = ensureUniqueElementData()->m_inlineStyle; 152 152 if (!inlineStyle) 153 153 inlineStyle = StylePropertySet::create(strictToCSSParserMode(isHTMLElement() && !document()->inQuirksMode())); … … 162 162 styleAttributeChanged(newValue); 163 163 else if (isPresentationAttribute(name)) { 164 attributeData()->m_presentationAttributeStyleIsDirty = true;164 elementData()->m_presentationAttributeStyleIsDirty = true; 165 165 setNeedsStyleRecalc(InlineStyleChange); 166 166 } … … 173 173 if (!inlineStyle() || !inlineStyle()->hasCSSOMWrapper()) 174 174 return 0; 175 PropertySetCSSStyleDeclaration* cssomWrapper = mutableAttributeData()->m_inlineStyle->cssStyleDeclaration();175 PropertySetCSSStyleDeclaration* cssomWrapper = ensureUniqueElementData()->m_inlineStyle->cssStyleDeclaration(); 176 176 ASSERT(cssomWrapper && cssomWrapper->parentElement() == this); 177 177 return cssomWrapper; … … 180 180 inline void StyledElement::setInlineStyleFromString(const AtomicString& newStyleString) 181 181 { 182 RefPtr<StylePropertySet>& inlineStyle = attributeData()->m_inlineStyle;182 RefPtr<StylePropertySet>& inlineStyle = elementData()->m_inlineStyle; 183 183 184 184 // Avoid redundant work if we're using shared attribute data with already parsed inline style. 185 if (inlineStyle && ! attributeData()->isMutable())185 if (inlineStyle && !elementData()->isUnique()) 186 186 return; 187 187 … … 206 206 if (PropertySetCSSStyleDeclaration* cssomWrapper = inlineStyleCSSOMWrapper()) 207 207 cssomWrapper->clearParentElement(); 208 mutableAttributeData()->m_inlineStyle.clear();208 ensureUniqueElementData()->m_inlineStyle.clear(); 209 209 } else if (document()->contentSecurityPolicy()->allowInlineStyle(document()->url(), startLineNumber)) 210 210 setInlineStyleFromString(newStyleString); 211 211 212 attributeData()->m_styleAttributeIsDirty = false;212 elementData()->m_styleAttributeIsDirty = false; 213 213 214 214 setNeedsStyleRecalc(InlineStyleChange); … … 219 219 { 220 220 setNeedsStyleRecalc(InlineStyleChange); 221 ASSERT( attributeData());222 attributeData()->m_styleAttributeIsDirty = true;221 ASSERT(elementData()); 222 elementData()->m_styleAttributeIsDirty = true; 223 223 InspectorInstrumentation::didInvalidateStyleAttr(document(), this); 224 224 } … … 266 266 void StyledElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const 267 267 { 268 if (const StylePropertySet* inlineStyle = attributeData() ? attributeData()->inlineStyle() : 0)268 if (const StylePropertySet* inlineStyle = elementData() ? elementData()->inlineStyle() : 0) 269 269 inlineStyle->addSubresourceStyleURLs(urls, document()->elementSheet()->contents()); 270 270 } … … 341 341 } 342 342 343 // ImmutableElementAttributeData doesn't store presentation attribute style, so make sure we have a MutableElementAttributeData.344 Element AttributeData* attributeData = mutableAttributeData();345 346 attributeData->m_presentationAttributeStyleIsDirty = false;347 attributeData->setPresentationAttributeStyle(style->isEmpty() ? 0 : style);343 // ShareableElementData doesn't store presentation attribute style, so make sure we have a UniqueElementData. 344 ElementData* elementData = ensureUniqueElementData(); 345 346 elementData->m_presentationAttributeStyleIsDirty = false; 347 elementData->setPresentationAttributeStyle(style->isEmpty() ? 0 : style); 348 348 349 349 if (!cacheHash || cacheIterator->value) -
trunk/Source/WebCore/dom/StyledElement.h
r135101 r142791 41 41 void invalidateStyleAttribute(); 42 42 43 const StylePropertySet* inlineStyle() const { return attributeData() ? attributeData()->m_inlineStyle.get() : 0; }43 const StylePropertySet* inlineStyle() const { return elementData() ? elementData()->m_inlineStyle.get() : 0; } 44 44 StylePropertySet* ensureMutableInlineStyle(); 45 45 … … 87 87 inline void StyledElement::invalidateStyleAttribute() 88 88 { 89 ASSERT( attributeData());90 attributeData()->m_styleAttributeIsDirty = true;89 ASSERT(elementData()); 90 elementData()->m_styleAttributeIsDirty = true; 91 91 } 92 92 93 93 inline const StylePropertySet* StyledElement::presentationAttributeStyle() 94 94 { 95 if (! attributeData())95 if (!elementData()) 96 96 return 0; 97 if ( attributeData()->m_presentationAttributeStyleIsDirty)97 if (elementData()->m_presentationAttributeStyleIsDirty) 98 98 rebuildPresentationAttributeStyle(); 99 return attributeData()->presentationAttributeStyle();99 return elementData()->presentationAttributeStyle(); 100 100 } 101 101 -
trunk/Source/WebCore/html/ClassList.cpp
r138691 r142791 69 69 return *m_classNamesForQuirksMode.get(); 70 70 } 71 return m_element-> attributeData()->classNames();71 return m_element->elementData()->classNames(); 72 72 } 73 73 -
trunk/Source/WebCore/html/HTMLInputElement.cpp
r142592 r142791 516 516 517 517 if (didRespectHeightAndWidth != m_inputType->shouldRespectHeightAndWidthAttributes()) { 518 ASSERT( attributeData());518 ASSERT(elementData()); 519 519 if (Attribute* height = getAttributeItem(heightAttr)) 520 520 attributeChanged(heightAttr, height->value()); -
trunk/Source/WebCore/html/parser/HTMLConstructionSite.cpp
r142641 r142791 212 212 for (unsigned i = 0; i < token->attributes().size(); ++i) { 213 213 const Attribute& tokenAttribute = token->attributes().at(i); 214 if (!element-> attributeData() || !element->getAttributeItem(tokenAttribute.name()))214 if (!element->elementData() || !element->getAttributeItem(tokenAttribute.name())) 215 215 element->setAttribute(tokenAttribute.name(), tokenAttribute.value()); 216 216 } -
trunk/Source/WebCore/svg/SVGElement.cpp
r141524 r142791 545 545 void SVGElement::updateAnimatedSVGAttribute(const QualifiedName& name) const 546 546 { 547 if (! attributeData() || !attributeData()->m_animatedSVGAttributesAreDirty)547 if (!elementData() || !elementData()->m_animatedSVGAttributesAreDirty) 548 548 return; 549 549 … … 551 551 if (name == anyQName()) { 552 552 nonConstThis->localAttributeToPropertyMap().synchronizeProperties(nonConstThis); 553 attributeData()->m_animatedSVGAttributesAreDirty = false;553 elementData()->m_animatedSVGAttributesAreDirty = false; 554 554 } else 555 555 nonConstThis->localAttributeToPropertyMap().synchronizeProperty(nonConstThis, name); -
trunk/Source/WebCore/svg/SVGElement.h
r142714 r142791 80 80 virtual AffineTransform* supplementalTransform() { return 0; } 81 81 82 void invalidateSVGAttributes() { mutableAttributeData()->m_animatedSVGAttributesAreDirty = true; }82 void invalidateSVGAttributes() { ensureUniqueElementData()->m_animatedSVGAttributesAreDirty = true; } 83 83 84 84 const HashSet<SVGElementInstance*>& instancesForElement() const; -
trunk/Source/WebCore/xml/parser/XMLDocumentParserQt.cpp
r142375 r142791 147 147 QXmlStreamNamespaceDeclarations namespaces; 148 148 for (Element* element = elemStack.last(); !elemStack.isEmpty(); elemStack.removeLast()) { 149 if (const Element AttributeData* attrs = element->updatedAttributeData()) {149 if (const ElementData* attrs = element->elementDataWithSynchronizedAttributes()) { 150 150 for (unsigned i = 0; i < attrs->length(); i++) { 151 151 const Attribute* attr = attrs->attributeItem(i);
Note: See TracChangeset
for help on using the changeset viewer.