Title: [129318] trunk/Source/WebCore
Revision
129318
Author
[email protected]
Date
2012-09-23 17:57:54 -0700 (Sun, 23 Sep 2012)

Log Message

Enable ElementAttributeData sharing for non-HTML elements.
<http://webkit.org/b/97413>

Reviewed by Anders Carlsson.

Use the whole qualified tag name when creating the ElementAttributeData cache key
instead of just the localName(). This allows sharing and caching of attribute data
for non-HTML elements and makes the code a little cleaner.

* dom/Element.cpp:
(WebCore::Element::parserSetAttributes):

    Enable the ElementAttributeData sharing path for non-HTML elements.

* dom/ElementAttributeData.h:

    Make immutableAttributeArray() public so Document can call it instead of getting
    the raw data address from a const_cast'ed attributeItem(0).

* dom/Document.cpp:
(WebCore::ImmutableAttributeDataCacheKey::ImmutableAttributeDataCacheKey):
(WebCore::ImmutableAttributeDataCacheKey::operator!=):
(WebCore::ImmutableAttributeDataCacheKey::hash):
(ImmutableAttributeDataCacheKey):
(WebCore::ImmutableAttributeDataCacheEntry::ImmutableAttributeDataCacheEntry):
(ImmutableAttributeDataCacheEntry):
(WebCore::Document::cachedImmutableAttributeData):

    Let the immutable attribute data cache use a QualifiedName/attributes key
    instead of the AtomicString/attributes we were using before. We still grab the
    existingHash() from the QualifiedName::localName() and use that for the actual
    HashMap key.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (129317 => 129318)


--- trunk/Source/WebCore/ChangeLog	2012-09-23 23:37:01 UTC (rev 129317)
+++ trunk/Source/WebCore/ChangeLog	2012-09-24 00:57:54 UTC (rev 129318)
@@ -1,3 +1,38 @@
+2012-09-23  Andreas Kling  <[email protected]>
+
+        Enable ElementAttributeData sharing for non-HTML elements.
+        <http://webkit.org/b/97413>
+
+        Reviewed by Anders Carlsson.
+
+        Use the whole qualified tag name when creating the ElementAttributeData cache key
+        instead of just the localName(). This allows sharing and caching of attribute data
+        for non-HTML elements and makes the code a little cleaner.
+
+        * dom/Element.cpp:
+        (WebCore::Element::parserSetAttributes):
+
+            Enable the ElementAttributeData sharing path for non-HTML elements.
+
+        * dom/ElementAttributeData.h:
+
+            Make immutableAttributeArray() public so Document can call it instead of getting
+            the raw data address from a const_cast'ed attributeItem(0).
+
+        * dom/Document.cpp:
+        (WebCore::ImmutableAttributeDataCacheKey::ImmutableAttributeDataCacheKey):
+        (WebCore::ImmutableAttributeDataCacheKey::operator!=):
+        (WebCore::ImmutableAttributeDataCacheKey::hash):
+        (ImmutableAttributeDataCacheKey):
+        (WebCore::ImmutableAttributeDataCacheEntry::ImmutableAttributeDataCacheEntry):
+        (ImmutableAttributeDataCacheEntry):
+        (WebCore::Document::cachedImmutableAttributeData):
+
+            Let the immutable attribute data cache use a QualifiedName/attributes key
+            instead of the AtomicString/attributes we were using before. We still grab the
+            existingHash() from the QualifiedName::localName() and use that for the actual
+            HashMap key.
+
 2012-09-23  Mike West  <[email protected]>
 
         Measure the usage of the "X-WebKit-CSP" header in the hopes of dropping the prefix completely.

Modified: trunk/Source/WebCore/dom/Document.cpp (129317 => 129318)


--- trunk/Source/WebCore/dom/Document.cpp	2012-09-23 23:37:01 UTC (rev 129317)
+++ trunk/Source/WebCore/dom/Document.cpp	2012-09-24 00:57:54 UTC (rev 129318)
@@ -127,6 +127,7 @@
 #include "PointerLockController.h"
 #include "PopStateEvent.h"
 #include "ProcessingInstruction.h"
+#include "QualifiedName.h"
 #include "RegisteredEventListener.h"
 #include "RenderArena.h"
 #include "RenderNamedFlowThread.h"
@@ -6314,23 +6315,16 @@
 #endif
 
 class ImmutableAttributeDataCacheKey {
-    WTF_MAKE_FAST_ALLOCATED;
 public:
-    ImmutableAttributeDataCacheKey()
-        : m_localName(0)
-        , m_attributes(0)
-        , m_attributeCount(0)
-    { }
-
-    ImmutableAttributeDataCacheKey(const AtomicString& localName, const Attribute* attributes, unsigned attributeCount)
-        : m_localName(localName.impl())
+    ImmutableAttributeDataCacheKey(const QualifiedName& tagName, const Attribute* attributes, unsigned attributeCount)
+        : m_tagQName(tagName)
         , m_attributes(attributes)
         , m_attributeCount(attributeCount)
     { }
 
     bool operator!=(const ImmutableAttributeDataCacheKey& other) const
     {
-        if (m_localName != other.m_localName)
+        if (m_tagQName != other.m_tagQName)
             return true;
         if (m_attributeCount != other.m_attributeCount)
             return true;
@@ -6340,16 +6334,21 @@
     unsigned hash() const
     {
         unsigned attributeHash = StringHasher::hashMemory(m_attributes, m_attributeCount * sizeof(Attribute));
-        return WTF::pairIntHash(m_localName->existingHash(), attributeHash);
+        return WTF::pairIntHash(m_tagQName.localName().impl()->existingHash(), attributeHash);
     }
 
 private:
-    AtomicStringImpl* m_localName;
+    QualifiedName m_tagQName;
     const Attribute* m_attributes;
     unsigned m_attributeCount;
 };
 
 struct ImmutableAttributeDataCacheEntry {
+    ImmutableAttributeDataCacheEntry(const ImmutableAttributeDataCacheKey& k, PassRefPtr<ElementAttributeData> v)
+        : key(k)
+        , value(v)
+    { }
+
     ImmutableAttributeDataCacheKey key;
     RefPtr<ElementAttributeData> value;
 };
@@ -6358,7 +6357,7 @@
 {
     ASSERT(!attributes.isEmpty());
 
-    ImmutableAttributeDataCacheKey cacheKey(element->localName(), attributes.data(), attributes.size());
+    ImmutableAttributeDataCacheKey cacheKey(element->tagQName(), attributes.data(), attributes.size());
     unsigned cacheHash = cacheKey.hash();
 
     ImmutableAttributeDataCache::iterator cacheIterator = m_immutableAttributeDataCache.add(cacheHash, nullptr).iterator;
@@ -6374,12 +6373,8 @@
     if (!cacheHash || cacheIterator->second)
         return attributeData.release();
 
-    OwnPtr<ImmutableAttributeDataCacheEntry> newEntry = adoptPtr(new ImmutableAttributeDataCacheEntry);
-    newEntry->key = ImmutableAttributeDataCacheKey(element->localName(), const_cast<const ElementAttributeData*>(attributeData.get())->attributeItem(0), attributeData->length());
-    newEntry->value = attributeData;
+    cacheIterator->second = adoptPtr(new ImmutableAttributeDataCacheEntry(ImmutableAttributeDataCacheKey(element->tagQName(), attributeData->immutableAttributeArray(), attributeData->length()), attributeData));
 
-    cacheIterator->second = newEntry.release();
-
     return attributeData.release();
 }
 

Modified: trunk/Source/WebCore/dom/Element.cpp (129317 => 129318)


--- trunk/Source/WebCore/dom/Element.cpp	2012-09-23 23:37:01 UTC (rev 129317)
+++ trunk/Source/WebCore/dom/Element.cpp	2012-09-24 00:57:54 UTC (rev 129318)
@@ -843,13 +843,10 @@
     }
 
     // When the document is in parsing state, we cache immutable ElementAttributeData objects with the
-    // input attribute vector as key. (This cache is held by Document.)
+    // input attribute vector (and the tag name) as key. (This cache is held by Document.)
     if (!document() || !document()->parsing())
         m_attributeData = ElementAttributeData::createImmutable(filteredAttributes);
-    else if (!isHTMLElement()) {
-        // FIXME: Support attribute data sharing for non-HTML elements.
-        m_attributeData = ElementAttributeData::createImmutable(filteredAttributes);
-    } else
+    else
         m_attributeData = document()->cachedImmutableAttributeData(this, filteredAttributes);
 
     // Iterate over the set of attributes we already have on the stack in case

Modified: trunk/Source/WebCore/dom/ElementAttributeData.h (129317 => 129318)


--- trunk/Source/WebCore/dom/ElementAttributeData.h	2012-09-23 23:37:01 UTC (rev 129317)
+++ trunk/Source/WebCore/dom/ElementAttributeData.h	2012-09-24 00:57:54 UTC (rev 129318)
@@ -97,6 +97,7 @@
     void reportMemoryUsage(MemoryObjectInfo*) const;
 
     bool isMutable() const { return m_isMutable; }
+    const Attribute* immutableAttributeArray() const;
 
 protected:
     ElementAttributeData()
@@ -133,7 +134,6 @@
 
     Vector<Attribute, 4>& mutableAttributeVector();
     const Vector<Attribute, 4>& mutableAttributeVector() const;
-    const Attribute* immutableAttributeArray() const;
 };
 
 class ImmutableElementAttributeData : public ElementAttributeData {
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to