QualifiedName should use RefPtr<QualifiedNameImpl> internally.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 5 Jul 2014 01:29:55 +0000 (01:29 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 5 Jul 2014 01:29:55 +0000 (01:29 +0000)
<https://webkit.org/b/132796>

We were not inlining ~QualifiedName() and it was showing up in some
profiles (over 1% on dom-attr.html.)

This patch modernizes QualifiedName a bit by using RefPtr to store
the QualifiedNameImpl instead of doing manual ref() and deref()
in out-of-line functions.

Reviewed by Darin Adler.

* WebCore.exp.in:
* dom/QualifiedName.cpp:
(WebCore::QNameComponentsTranslator::translate):
(WebCore::QualifiedName::QualifiedName):
(WebCore::QualifiedName::~QualifiedName): Deleted.
(WebCore::QualifiedName::deref): Deleted.
* dom/QualifiedName.h:
(WebCore::QualifiedName::QualifiedNameImpl::create):
(WebCore::QualifiedName::QualifiedName):
(WebCore::QualifiedName::isHashTableDeletedValue):
(WebCore::QualifiedName::~QualifiedName):
(WebCore::QualifiedName::operator=):
(WebCore::QualifiedName::impl):
(WebCore::QualifiedName::ref): Deleted.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@170816 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/dom/QualifiedName.cpp
Source/WebCore/dom/QualifiedName.h

index 1d05b44..3b2d0b3 100644 (file)
@@ -1,3 +1,32 @@
+2014-05-10  Andreas Kling  <akling@apple.com>
+
+        QualifiedName should use RefPtr<QualifiedNameImpl> internally.
+        <https://webkit.org/b/132796>
+
+        We were not inlining ~QualifiedName() and it was showing up in some
+        profiles (over 1% on dom-attr.html.)
+
+        This patch modernizes QualifiedName a bit by using RefPtr to store
+        the QualifiedNameImpl instead of doing manual ref() and deref()
+        in out-of-line functions.
+
+        Reviewed by Darin Adler.
+
+        * WebCore.exp.in:
+        * dom/QualifiedName.cpp:
+        (WebCore::QNameComponentsTranslator::translate):
+        (WebCore::QualifiedName::QualifiedName):
+        (WebCore::QualifiedName::~QualifiedName): Deleted.
+        (WebCore::QualifiedName::deref): Deleted.
+        * dom/QualifiedName.h:
+        (WebCore::QualifiedName::QualifiedNameImpl::create):
+        (WebCore::QualifiedName::QualifiedName):
+        (WebCore::QualifiedName::isHashTableDeletedValue):
+        (WebCore::QualifiedName::~QualifiedName):
+        (WebCore::QualifiedName::operator=):
+        (WebCore::QualifiedName::impl):
+        (WebCore::QualifiedName::ref): Deleted.
+
 2014-07-04  Dean Jackson  <dino@apple.com>
 
         [iOS] [Media] Prevent page zoom if it started in the video element
index 8f4ce66..6acc3a3 100644 (file)
@@ -310,7 +310,6 @@ __ZN7WebCore13NodeTraversal13deepLastChildEPNS_4NodeE
 __ZN7WebCore13NodeTraversal19nextAncestorSiblingEPKNS_4NodeE
 __ZN7WebCore13NodeTraversal19nextAncestorSiblingEPKNS_4NodeES3_
 __ZN7WebCore13PageThrottler7startedEv
-__ZN7WebCore13QualifiedNameD1Ev
 __ZN7WebCore13ResourceErrorC1EP7NSError
 __ZN7WebCore13ResourceErrorC1EP9__CFError
 __ZN7WebCore13SQLResultDoneE
index 3681a14..fd79bda 100644 (file)
@@ -68,7 +68,7 @@ struct QNameComponentsTranslator {
     }
     static void translate(QualifiedName::QualifiedNameImpl*& location, const QualifiedNameComponents& components, unsigned)
     {
-        location = QualifiedName::QualifiedNameImpl::create(components.m_prefix, components.m_localName, components.m_namespace).leakRef();
+        location = &QualifiedName::QualifiedNameImpl::create(components.m_prefix, components.m_localName, components.m_namespace).leakRef();
     }
 };
 
@@ -80,26 +80,9 @@ static inline QNameSet& qualifiedNameCache()
 
 QualifiedName::QualifiedName(const AtomicString& p, const AtomicString& l, const AtomicString& n)
 {
-    QualifiedNameComponents components = { p.impl(), l.impl(), n.isEmpty() ? nullAtom.impl() : n.impl() };
+    QualifiedNameComponents components = { p.impl(), l.impl(), n.isEmpty() ? nullptr : n.impl() };
     QNameSet::AddResult addResult = qualifiedNameCache().add<QNameComponentsTranslator>(components);
-    m_impl = *addResult.iterator;
-    if (!addResult.isNewEntry)
-        m_impl->ref();
-}
-
-QualifiedName::~QualifiedName()
-{
-    deref();
-}
-
-void QualifiedName::deref()
-{
-#ifdef QNAME_DEFAULT_CONSTRUCTOR
-    if (!m_impl)
-        return;
-#endif
-    ASSERT(!isHashTableDeletedValue());
-    m_impl->deref();
+    m_impl = addResult.isNewEntry ? adoptRef(*addResult.iterator) : *addResult.iterator;
 }
 
 QualifiedName::QualifiedNameImpl::~QualifiedNameImpl()
index c64ac2d..1a56e9d 100644 (file)
@@ -39,9 +39,9 @@ class QualifiedName {
 public:
     class QualifiedNameImpl : public RefCounted<QualifiedNameImpl> {
     public:
-        static PassRefPtr<QualifiedNameImpl> create(const AtomicString& prefix, const AtomicString& localName, const AtomicString& namespaceURI)
+        static PassRef<QualifiedNameImpl> create(const AtomicString& prefix, const AtomicString& localName, const AtomicString& namespaceURI)
         {
-            return adoptRef(new QualifiedNameImpl(prefix, localName, namespaceURI));
+            return adoptRef(*new QualifiedNameImpl(prefix, localName, namespaceURI));
         }
 
         ~QualifiedNameImpl();
@@ -71,15 +71,14 @@ public:
     };
 
     QualifiedName(const AtomicString& prefix, const AtomicString& localName, const AtomicString& namespaceURI);
-    explicit QualifiedName(WTF::HashTableDeletedValueType) : m_impl(hashTableDeletedValue()) { }
-    bool isHashTableDeletedValue() const { return m_impl == hashTableDeletedValue(); }
-    ~QualifiedName();
+    explicit QualifiedName(WTF::HashTableDeletedValueType) : m_impl(WTF::HashTableDeletedValue) { }
+    bool isHashTableDeletedValue() const { return m_impl.isHashTableDeletedValue(); }
 #ifdef QNAME_DEFAULT_CONSTRUCTOR
-    QualifiedName() : m_impl(0) { }
+    QualifiedName() { }
 #endif
 
-    QualifiedName(const QualifiedName& other) : m_impl(other.m_impl) { ref(); }
-    const QualifiedName& operator=(const QualifiedName& other) { other.ref(); deref(); m_impl = other.m_impl; return *this; }
+    QualifiedName(const QualifiedName& other) : m_impl(other.m_impl) { }
+    const QualifiedName& operator=(const QualifiedName& other) { m_impl = other.m_impl; return *this; }
 
     bool operator==(const QualifiedName& other) const { return m_impl == other.m_impl; }
     bool operator!=(const QualifiedName& other) const { return !(*this == other); }
@@ -100,7 +99,7 @@ public:
 
     String toString() const;
 
-    QualifiedNameImpl* impl() const { return m_impl; }
+    QualifiedNameImpl* impl() const { return m_impl.get(); }
 #if ENABLE(CSS_SELECTOR_JIT)
     static ptrdiff_t implMemoryOffset() { return OBJECT_OFFSETOF(QualifiedName, m_impl); }
 #endif // ENABLE(CSS_SELECTOR_JIT)
@@ -109,12 +108,9 @@ public:
     static void init();
 
 private:
-    void ref() const { m_impl->ref(); }
-    void deref();
-
     static QualifiedNameImpl* hashTableDeletedValue() { return RefPtr<QualifiedNameImpl>::hashTableDeletedValue(); }
     
-    QualifiedNameImpl* m_impl;
+    RefPtr<QualifiedNameImpl> m_impl;
 };
 
 #ifndef WEBCORE_QUALIFIEDNAME_HIDE_GLOBALS