Title: [176873] trunk/Source
Revision
176873
Author
[email protected]
Date
2014-12-05 14:20:49 -0800 (Fri, 05 Dec 2014)

Log Message

PassRef should deref on destruction if pointee was not moved.
<https://webkit.org/b/139309>

Reviewed by Antti Koivisto.

Source/WebCore:

Remove calls to PassRef::dropRef() since it's no longer necessary to manually
notify PassRef that you didn't move the pointee.

* rendering/RenderElement.cpp:
(WebCore::RenderElement::createFor):
(WebCore::RenderElement::setStyle):
* style/StyleResolveTree.cpp:
(WebCore::Style::resolveTree):

Source/WTF:

Let PassRef become nullptr internally after having WTF::move()'d the pointee.
This means that PassRef is now essentially a PassRefPtr that can only be
constructed with a non-null pointee.

This should make it possible for all ::create()-style construction helpers to
return PassRef, removing a branch in each case.

* wtf/PassRef.h:
(WTF::PassRef<T>::PassRef):
(WTF::PassRef<T>::~PassRef):
(WTF::PassRef<T>::get):
(WTF::PassRef<T>::ptr):
(WTF::PassRef<T>::leakRef):
(WTF::PassRef<T>::dropRef): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (176872 => 176873)


--- trunk/Source/WTF/ChangeLog	2014-12-05 22:13:18 UTC (rev 176872)
+++ trunk/Source/WTF/ChangeLog	2014-12-05 22:20:49 UTC (rev 176873)
@@ -1,3 +1,25 @@
+2014-12-05  Andreas Kling  <[email protected]>
+
+        PassRef should deref on destruction if pointee was not moved.
+        <https://webkit.org/b/139309>
+
+        Reviewed by Antti Koivisto.
+
+        Let PassRef become nullptr internally after having WTF::move()'d the pointee.
+        This means that PassRef is now essentially a PassRefPtr that can only be
+        constructed with a non-null pointee.
+
+        This should make it possible for all ::create()-style construction helpers to
+        return PassRef, removing a branch in each case.
+
+        * wtf/PassRef.h:
+        (WTF::PassRef<T>::PassRef):
+        (WTF::PassRef<T>::~PassRef):
+        (WTF::PassRef<T>::get):
+        (WTF::PassRef<T>::ptr):
+        (WTF::PassRef<T>::leakRef):
+        (WTF::PassRef<T>::dropRef): Deleted.
+
 2014-12-05  Jer Noble  <[email protected]>
 
         [WTF] MediaTime should support round-tripping from and to doubles.

Modified: trunk/Source/WTF/wtf/PassRef.h (176872 => 176873)


--- trunk/Source/WTF/wtf/PassRef.h	2014-12-05 22:13:18 UTC (rev 176872)
+++ trunk/Source/WTF/wtf/PassRef.h	2014-12-05 22:20:49 UTC (rev 176873)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (C) 2013 Apple Inc. All rights reserved.
+ *  Copyright (C) 2013-2014 Apple Inc. All rights reserved.
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Library General Public
@@ -49,12 +49,9 @@
     const T* ptr() const;
     T* ptr();
 
-    void dropRef();
     T& leakRef() WARN_UNUSED_RETURN;
 
-#ifndef NDEBUG
     ~PassRef();
-#endif
 
 private:
     friend PassRef adoptRef<T>(T&);
@@ -67,103 +64,73 @@
     enum AdoptTag { Adopt };
     PassRef(T&, AdoptTag);
 
-    T& m_reference;
-
-#ifndef NDEBUG
+    T* m_ptr;
     bool m_gaveUpReference;
-#endif
 };
 
 template<typename T> inline PassRef<T>::PassRef(T& reference)
-    : m_reference(reference)
-#ifndef NDEBUG
-    , m_gaveUpReference(false)
-#endif
+    : m_ptr(&reference)
 {
-    reference.ref();
+    m_ptr->ref();
 }
 
 template<typename T> inline PassRef<T>::PassRef(PassRef&& other)
-    : m_reference(other.leakRef())
-#ifndef NDEBUG
-    , m_gaveUpReference(false)
-#endif
+    : m_ptr(&other.leakRef())
 {
 }
 
 template<typename T> template<typename U> inline PassRef<T>::PassRef(PassRef<U> other)
-    : m_reference(other.leakRef())
-#ifndef NDEBUG
-    , m_gaveUpReference(false)
-#endif
+    : m_ptr(&other.leakRef())
 {
 }
 
 template<typename T> template<typename U> inline PassRef<T>::PassRef(const Ref<U>& other)
-    : m_reference(static_cast<T&>(const_cast<U&>(other.get())))
-#ifndef NDEBUG
-    , m_gaveUpReference(false)
-#endif
+    : m_ptr(static_cast<T*>(const_cast<U*>(other.ptr())))
 {
-    m_reference.ref();
+    ASSERT(m_ptr);
+    m_ptr->ref();
 }
 
-#ifndef NDEBUG
-
 template<typename T> PassRef<T>::~PassRef()
 {
-    ASSERT(m_gaveUpReference);
+    if (m_ptr)
+        m_ptr->deref();
 }
 
-#endif
-
-template<typename T> inline void PassRef<T>::dropRef()
-{
-    ASSERT(!m_gaveUpReference);
-    m_reference.deref();
-#ifndef NDEBUG
-    m_gaveUpReference = true;
-#endif
-}
-
 template<typename T> inline const T& PassRef<T>::get() const
 {
-    ASSERT(!m_gaveUpReference);
-    return m_reference;
+    ASSERT(m_ptr);
+    return *m_ptr;
 }
 
 template<typename T> inline T& PassRef<T>::get()
 {
-    ASSERT(!m_gaveUpReference);
-    return m_reference;
+    ASSERT(m_ptr);
+    return *m_ptr;
 }
 
 template<typename T> const T* PassRef<T>::ptr() const
 {
-    ASSERT(!m_gaveUpReference);
-    return &m_reference;
+    ASSERT(m_ptr);
+    return m_ptr;
 }
 
 template<typename T> T* PassRef<T>::ptr()
 {
-    ASSERT(!m_gaveUpReference);
-    return &m_reference;
+    ASSERT(m_ptr);
+    return m_ptr;
 }
 
 template<typename T> inline T& PassRef<T>::leakRef()
 {
-#ifndef NDEBUG
-    ASSERT(!m_gaveUpReference);
-    m_gaveUpReference = true;
-#endif
-    return m_reference;
+    ASSERT(m_ptr);
+    T* leakedPtr = m_ptr;
+    m_ptr = nullptr;
+    return *leakedPtr;
 }
 
 template<typename T> inline PassRef<T>::PassRef(T& reference, AdoptTag)
-    : m_reference(reference)
-#ifndef NDEBUG
-    , m_gaveUpReference(false)
-#endif
+    : m_ptr(&reference)
 {
 }
 

Modified: trunk/Source/WebCore/ChangeLog (176872 => 176873)


--- trunk/Source/WebCore/ChangeLog	2014-12-05 22:13:18 UTC (rev 176872)
+++ trunk/Source/WebCore/ChangeLog	2014-12-05 22:20:49 UTC (rev 176873)
@@ -1,3 +1,19 @@
+2014-12-05  Andreas Kling  <[email protected]>
+
+        PassRef should deref on destruction if pointee was not moved.
+        <https://webkit.org/b/139309>
+
+        Reviewed by Antti Koivisto.
+
+        Remove calls to PassRef::dropRef() since it's no longer necessary to manually
+        notify PassRef that you didn't move the pointee.
+
+        * rendering/RenderElement.cpp:
+        (WebCore::RenderElement::createFor):
+        (WebCore::RenderElement::setStyle):
+        * style/StyleResolveTree.cpp:
+        (WebCore::Style::resolveTree):
+
 2014-12-05  Benjamin Poulain  <[email protected]>
 
         Fix style sharing with the "type" and "readonly" attributes

Modified: trunk/Source/WebCore/rendering/RenderElement.cpp (176872 => 176873)


--- trunk/Source/WebCore/rendering/RenderElement.cpp	2014-12-05 22:13:18 UTC (rev 176872)
+++ trunk/Source/WebCore/rendering/RenderElement.cpp	2014-12-05 22:20:49 UTC (rev 176873)
@@ -159,7 +159,6 @@
         return createRenderer<RenderRubyText>(element, WTF::move(style));
     switch (style.get().display()) {
     case NONE:
-        style.dropRef();
         return nullptr;
     case INLINE:
         return createRenderer<RenderInline>(element, WTF::move(style));
@@ -399,7 +398,6 @@
         ASSERT(!isRenderIFrame());
         ASSERT(!isEmbeddedObject());
         ASSERT(!isCanvas());
-        style.dropRef();
         return;
     }
 

Modified: trunk/Source/WebCore/style/StyleResolveTree.cpp (176872 => 176873)


--- trunk/Source/WebCore/style/StyleResolveTree.cpp	2014-12-05 22:13:18 UTC (rev 176872)
+++ trunk/Source/WebCore/style/StyleResolveTree.cpp	2014-12-05 22:20:49 UTC (rev 176873)
@@ -984,8 +984,6 @@
         Style::Change documentChange = determineChange(documentStyle.get(), document.renderView()->style());
         if (documentChange != NoChange)
             document.renderView()->setStyle(WTF::move(documentStyle));
-        else
-            documentStyle.dropRef();
     }
 
     Element* documentElement = document.documentElement();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to