⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 243686 in webkit


Ignore:
Timestamp:
Mar 31, 2019, 7:03:14 PM (7 years ago)
Author:
rniwa@webkit.org
Message:

Reduce the size of Node::deref by eliminating an explicit parentNode check
https://bugs.webkit.org/show_bug.cgi?id=195776

Reviewed by Darin Adler.

Address post-commit review comments.

  • dom/Document.cpp:

(WebCore::Document::removedLastRef):

  • dom/Node.cpp:

(WebCore::Node::~Node):
(WebCore::Node::removedLastRef):

  • dom/Node.h:

(WebCore::Node::deref):
(WebCore::Node::setParentNode):

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r243683 r243686  
     12019-03-31  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Reduce the size of Node::deref by eliminating an explicit parentNode check
     4        https://bugs.webkit.org/show_bug.cgi?id=195776
     5
     6        Reviewed by Darin Adler.
     7
     8        Address post-commit review comments.
     9
     10        * dom/Document.cpp:
     11        (WebCore::Document::removedLastRef):
     12        * dom/Node.cpp:
     13        (WebCore::Node::~Node):
     14        (WebCore::Node::removedLastRef):
     15        * dom/Node.h:
     16        (WebCore::Node::deref):
     17        (WebCore::Node::setParentNode):
     18
    1192019-03-31  Sam Weinig  <weinig@apple.com>
    220
  • trunk/Source/WebCore/dom/Document.cpp

    r243666 r243686  
    669669    if (m_referencingNodeCount) {
    670670        // Node::removedLastRef doesn't set refCount() to zero because it's not observable.
    671         // But we need to remember that our refCount reached zero in subsequent calls to decrementReferencingNodeCount()
     671        // But we need to remember that our refCount reached zero in subsequent calls to decrementReferencingNodeCount().
    672672        m_refCountAndParentBit = 0;
    673673
  • trunk/Source/WebCore/dom/Node.cpp

    r243249 r243686  
    333333{
    334334    ASSERT(isMainThread());
    335     // We set m_refCount to 2 before calling delete to avoid double destruction through use of Ref<T>/RefPtr<T>.
    336     // This is a security mitigation in case of programmer errorm (caught by a debug assertion).
    337335    ASSERT(m_refCountAndParentBit == s_refCountIncrement);
    338336    ASSERT(m_deletionHasBegun);
     
    25152513void Node::removedLastRef()
    25162514{
    2517     // This avoids double destruction even when there is a programming error to use Ref<T> / RefPtr<T> on this node.
    2518     // There are debug assertions in Node::ref() / Node::deref() to catch such a programming error.
    25192515    ASSERT(m_refCountAndParentBit == s_refCountIncrement);
    25202516
  • trunk/Source/WebCore/dom/Node.h

    r243233 r243686  
    619619
    620620    static constexpr uint32_t s_refCountIncrement = 2;
    621     static constexpr uint32_t s_refCountMask = ~static_cast<uint32_t>(0x1);
     621    static constexpr uint32_t s_refCountMask = ~static_cast<uint32_t>(1);
    622622
    623623    virtual void addSubresourceAttributeURLs(ListHashSet<URL>&) const { }
     
    708708    ASSERT(!m_inRemovedLastRefFunction);
    709709    ASSERT(!m_adoptionIsRequired);
    710     auto tempRefCount = m_refCountAndParentBit - s_refCountIncrement;
    711     if (!tempRefCount) {
     710    auto updatedRefCount = m_refCountAndParentBit - s_refCountIncrement;
     711    if (!updatedRefCount) {
     712        // Don't update m_refCountAndParentBit to avoid double destruction through use of Ref<T>/RefPtr<T>.
     713        // (This is a security mitigation in case of programmer error. It will ASSERT in debug builds.)
    712714#ifndef NDEBUG
    713715        m_inRemovedLastRefFunction = true;
     
    716718        return;
    717719    }
    718     m_refCountAndParentBit = tempRefCount;
     720    m_refCountAndParentBit = updatedRefCount;
    719721}
    720722
     
    742744    ASSERT(isMainThread());
    743745    m_parentNode = parent;
    744     auto refCountWithoutParentBit = m_refCountAndParentBit & s_refCountMask;
    745     m_refCountAndParentBit = refCountWithoutParentBit | !!parent;
     746    m_refCountAndParentBit = (m_refCountAndParentBit & s_refCountMask) | !!parent;
    746747}
    747748
Note: See TracChangeset for help on using the changeset viewer.