Title: [292627] trunk/Source
Revision
292627
Author
[email protected]
Date
2022-04-08 11:41:53 -0700 (Fri, 08 Apr 2022)

Log Message

static_pointer_cast<>() may cause some unnecessary ref-counting churn
https://bugs.webkit.org/show_bug.cgi?id=238961

Reviewed by Darin Adler.

Source/WebCore:

* dom/TreeScope.cpp:
(WebCore::TreeScope::elementFromPoint):
* editing/ApplyStyleCommand.cpp:
(WebCore::ApplyStyleCommand::splitAncestorsWithUnicodeBidi):
* editing/CompositeEditCommand.cpp:
(WebCore::CompositeEditCommand::textNodeForRebalance const):
* editing/DeleteSelectionCommand.cpp:
(WebCore::firstInSpecialElement):
(WebCore::lastInSpecialElement):
* html/canvas/WebGL2RenderingContext.cpp:
(WebCore::WebGL2RenderingContext::getFramebufferAttachmentParameter):
* html/canvas/WebGLRenderingContext.cpp:
(WebCore::WebGLRenderingContext::getFramebufferAttachmentParameter):
* page/ImageOverlayController.cpp:
(WebCore::ImageOverlayController::selectionQuadsDidChange):
* page/scrolling/mac/ScrollingCoordinatorMac.mm:
(WebCore::ScrollingCoordinatorMac::pageDestroyed):
* page/scrolling/nicosia/ScrollingCoordinatorNicosia.cpp:
(WebCore::ScrollingCoordinatorNicosia::pageDestroyed):

Source/WTF:

* wtf/RefPtr.h:
(WTF::adoptRef):
(WTF::static_pointer_cast):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (292626 => 292627)


--- trunk/Source/WTF/ChangeLog	2022-04-08 18:29:35 UTC (rev 292626)
+++ trunk/Source/WTF/ChangeLog	2022-04-08 18:41:53 UTC (rev 292627)
@@ -1,3 +1,14 @@
+2022-04-08  Chris Dumez  <[email protected]>
+
+        static_pointer_cast<>() may cause some unnecessary ref-counting churn
+        https://bugs.webkit.org/show_bug.cgi?id=238961
+
+        Reviewed by Darin Adler.
+
+        * wtf/RefPtr.h:
+        (WTF::adoptRef):
+        (WTF::static_pointer_cast):
+
 2022-04-08  Elliott Williams  <[email protected]>
 
         Unreviewed, reverting r292591.

Modified: trunk/Source/WTF/wtf/RefPtr.h (292626 => 292627)


--- trunk/Source/WTF/wtf/RefPtr.h	2022-04-08 18:29:35 UTC (rev 292626)
+++ trunk/Source/WTF/wtf/RefPtr.h	2022-04-08 18:41:53 UTC (rev 292627)
@@ -236,6 +236,13 @@
     return a != b.get(); 
 }
 
+template<typename T, typename U, typename V>
+inline RefPtr<T, U, V> adoptRef(T* p)
+{
+    adopted(p);
+    return RefPtr<T, U, V>(p, RefPtr<T, U, V>::Adopt);
+}
+
 template<typename T, typename U = RawPtrTraits<T>, typename V = DefaultRefDerefTraits<T>, typename X, typename Y, typename Z>
 inline RefPtr<T, U, V> static_pointer_cast(const RefPtr<X, Y, Z>& p)
 { 
@@ -242,18 +249,17 @@
     return RefPtr<T, U, V>(static_cast<T*>(p.get()));
 }
 
+template<typename T, typename U = RawPtrTraits<T>, typename V = DefaultRefDerefTraits<T>, typename X, typename Y, typename Z>
+inline RefPtr<T, U, V> static_pointer_cast(RefPtr<X, Y, Z>&& p)
+{
+    return adoptRef(static_cast<T*>(p.leakRef()));
+}
+
 template <typename T, typename U, typename V>
 struct IsSmartPtr<RefPtr<T, U, V>> {
     static constexpr bool value = true;
 };
 
-template<typename T, typename U, typename V>
-inline RefPtr<T, U, V> adoptRef(T* p)
-{
-    adopted(p);
-    return RefPtr<T, U, V>(p, RefPtr<T, U, V>::Adopt);
-}
-
 template<typename ExpectedType, typename ArgType, typename PtrTraits, typename RefDerefTraits>
 inline bool is(RefPtr<ArgType, PtrTraits, RefDerefTraits>& source)
 {

Modified: trunk/Source/WebCore/ChangeLog (292626 => 292627)


--- trunk/Source/WebCore/ChangeLog	2022-04-08 18:29:35 UTC (rev 292626)
+++ trunk/Source/WebCore/ChangeLog	2022-04-08 18:41:53 UTC (rev 292627)
@@ -1,3 +1,30 @@
+2022-04-08  Chris Dumez  <[email protected]>
+
+        static_pointer_cast<>() may cause some unnecessary ref-counting churn
+        https://bugs.webkit.org/show_bug.cgi?id=238961
+
+        Reviewed by Darin Adler.
+
+        * dom/TreeScope.cpp:
+        (WebCore::TreeScope::elementFromPoint):
+        * editing/ApplyStyleCommand.cpp:
+        (WebCore::ApplyStyleCommand::splitAncestorsWithUnicodeBidi):
+        * editing/CompositeEditCommand.cpp:
+        (WebCore::CompositeEditCommand::textNodeForRebalance const):
+        * editing/DeleteSelectionCommand.cpp:
+        (WebCore::firstInSpecialElement):
+        (WebCore::lastInSpecialElement):
+        * html/canvas/WebGL2RenderingContext.cpp:
+        (WebCore::WebGL2RenderingContext::getFramebufferAttachmentParameter):
+        * html/canvas/WebGLRenderingContext.cpp:
+        (WebCore::WebGLRenderingContext::getFramebufferAttachmentParameter):
+        * page/ImageOverlayController.cpp:
+        (WebCore::ImageOverlayController::selectionQuadsDidChange):
+        * page/scrolling/mac/ScrollingCoordinatorMac.mm:
+        (WebCore::ScrollingCoordinatorMac::pageDestroyed):
+        * page/scrolling/nicosia/ScrollingCoordinatorNicosia.cpp:
+        (WebCore::ScrollingCoordinatorNicosia::pageDestroyed):
+
 2022-04-08  Elliott Williams  <[email protected]>
 
         Unreviewed, reverting r292591.

Modified: trunk/Source/WebCore/dom/TreeScope.cpp (292626 => 292627)


--- trunk/Source/WebCore/dom/TreeScope.cpp	2022-04-08 18:29:35 UTC (rev 292626)
+++ trunk/Source/WebCore/dom/TreeScope.cpp	2022-04-08 18:41:53 UTC (rev 292627)
@@ -380,7 +380,7 @@
         node = retargetToScope(*node);
     }
 
-    return static_pointer_cast<Element>(node);
+    return static_pointer_cast<Element>(WTFMove(node));
 }
 
 Vector<RefPtr<Element>> TreeScope::elementsFromPoint(double clientX, double clientY)

Modified: trunk/Source/WebCore/editing/ApplyStyleCommand.cpp (292626 => 292627)


--- trunk/Source/WebCore/editing/ApplyStyleCommand.cpp	2022-04-08 18:29:35 UTC (rev 292626)
+++ trunk/Source/WebCore/editing/ApplyStyleCommand.cpp	2022-04-08 18:41:53 UTC (rev 292627)
@@ -498,7 +498,7 @@
             if (!nextHighestAncestorWithUnicodeBidi)
                 return static_pointer_cast<HTMLElement>(WTFMove(highestAncestorWithUnicodeBidi));
 
-            unsplitAncestor = static_pointer_cast<HTMLElement>(highestAncestorWithUnicodeBidi);
+            unsplitAncestor = static_pointer_cast<HTMLElement>(WTFMove(highestAncestorWithUnicodeBidi));
             highestAncestorWithUnicodeBidi = nextHighestAncestorWithUnicodeBidi;
         }
     }

Modified: trunk/Source/WebCore/editing/CompositeEditCommand.cpp (292626 => 292627)


--- trunk/Source/WebCore/editing/CompositeEditCommand.cpp	2022-04-08 18:29:35 UTC (rev 292626)
+++ trunk/Source/WebCore/editing/CompositeEditCommand.cpp	2022-04-08 18:41:53 UTC (rev 292627)
@@ -892,7 +892,7 @@
     if (position.anchorType() != Position::PositionIsOffsetInAnchor || !is<Text>(node))
         return nullptr;
 
-    auto textNode = static_pointer_cast<Text>(std::exchange(node, nullptr));
+    auto textNode = static_pointer_cast<Text>(WTFMove(node));
     if (!textNode->length())
         return nullptr;
 

Modified: trunk/Source/WebCore/editing/DeleteSelectionCommand.cpp (292626 => 292627)


--- trunk/Source/WebCore/editing/DeleteSelectionCommand.cpp	2022-04-08 18:29:35 UTC (rev 292626)
+++ trunk/Source/WebCore/editing/DeleteSelectionCommand.cpp	2022-04-08 18:41:53 UTC (rev 292627)
@@ -111,7 +111,7 @@
         VisiblePosition firstInElement = firstPositionInOrBeforeNode(node.get());
         if ((isRenderedTable(node.get()) && visiblePosition == firstInElement.next()) || visiblePosition == firstInElement) {
             RELEASE_ASSERT(is<HTMLElement>(node));
-            return static_pointer_cast<HTMLElement>(node);
+            return static_pointer_cast<HTMLElement>(WTFMove(node));
         }
     }
     return nullptr;
@@ -127,7 +127,7 @@
         VisiblePosition lastInElement = lastPositionInOrAfterNode(node.get());
         if ((isRenderedTable(node.get()) && visiblePosition == lastInElement.previous()) || visiblePosition == lastInElement) {
             RELEASE_ASSERT(is<HTMLElement>(node));
-            return static_pointer_cast<HTMLElement>(node);
+            return static_pointer_cast<HTMLElement>(WTFMove(node));
         }
     }
     return nullptr;

Modified: trunk/Source/WebCore/html/canvas/WebGL2RenderingContext.cpp (292626 => 292627)


--- trunk/Source/WebCore/html/canvas/WebGL2RenderingContext.cpp	2022-04-08 18:29:35 UTC (rev 292626)
+++ trunk/Source/WebCore/html/canvas/WebGL2RenderingContext.cpp	2022-04-08 18:41:53 UTC (rev 292627)
@@ -2890,8 +2890,8 @@
         return static_cast<unsigned>(GraphicsContextGL::RENDERBUFFER);
     case GraphicsContextGL::FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
         if (attachmentObject->isTexture())
-            return static_pointer_cast<WebGLTexture>(attachmentObject);
-        return static_pointer_cast<WebGLRenderbuffer>(attachmentObject);
+            return static_pointer_cast<WebGLTexture>(WTFMove(attachmentObject));
+        return static_pointer_cast<WebGLRenderbuffer>(WTFMove(attachmentObject));
     case GraphicsContextGL::FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
     case GraphicsContextGL::FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
     case GraphicsContextGL::FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:

Modified: trunk/Source/WebCore/html/canvas/WebGLRenderingContext.cpp (292626 => 292627)


--- trunk/Source/WebCore/html/canvas/WebGLRenderingContext.cpp	2022-04-08 18:29:35 UTC (rev 292626)
+++ trunk/Source/WebCore/html/canvas/WebGLRenderingContext.cpp	2022-04-08 18:41:53 UTC (rev 292627)
@@ -326,7 +326,7 @@
         case GraphicsContextGL::FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
             return static_cast<unsigned>(GraphicsContextGL::TEXTURE);
         case GraphicsContextGL::FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
-            return static_pointer_cast<WebGLTexture>(object);
+            return static_pointer_cast<WebGLTexture>(WTFMove(object));
         case GraphicsContextGL::FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
         case GraphicsContextGL::FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
         case GraphicsContextGL::FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING_EXT:
@@ -341,13 +341,13 @@
         case GraphicsContextGL::FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
             return static_cast<unsigned>(GraphicsContextGL::RENDERBUFFER);
         case GraphicsContextGL::FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
-            return static_pointer_cast<WebGLRenderbuffer>(object);
+            return static_pointer_cast<WebGLRenderbuffer>(WTFMove(object));
         case GraphicsContextGL::FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING_EXT: {
             if (!m_extsRGB) {
                 synthesizeGLError(GraphicsContextGL::INVALID_ENUM, "getFramebufferAttachmentParameter", "invalid parameter name for renderbuffer attachment");
                 return nullptr;
             }
-            RefPtr<WebGLRenderbuffer> renderBuffer = reinterpret_cast<WebGLRenderbuffer*>(object.get());
+            RefPtr renderBuffer = static_pointer_cast<WebGLRenderbuffer>(WTFMove(object));
             GCGLenum renderBufferFormat = renderBuffer->getInternalFormat();
             ASSERT(renderBufferFormat != GraphicsContextGL::SRGB_EXT && renderBufferFormat != GraphicsContextGL::SRGB_ALPHA_EXT);
             if (renderBufferFormat == GraphicsContextGL::SRGB8_ALPHA8_EXT)

Modified: trunk/Source/WebCore/page/ImageOverlayController.cpp (292626 => 292627)


--- trunk/Source/WebCore/page/ImageOverlayController.cpp	2022-04-08 18:29:35 UTC (rev 292626)
+++ trunk/Source/WebCore/page/ImageOverlayController.cpp	2022-04-08 18:41:53 UTC (rev 292627)
@@ -76,7 +76,7 @@
             return nullptr;
 
         if (RefPtr host = selectedRange->startContainer().shadowHost(); is<HTMLElement>(host))
-            return static_pointer_cast<HTMLElement>(host);
+            return static_pointer_cast<HTMLElement>(WTFMove(host));
 
         return nullptr;
     })();

Modified: trunk/Source/WebCore/page/scrolling/mac/ScrollingCoordinatorMac.mm (292626 => 292627)


--- trunk/Source/WebCore/page/scrolling/mac/ScrollingCoordinatorMac.mm	2022-04-08 18:29:35 UTC (rev 292626)
+++ trunk/Source/WebCore/page/scrolling/mac/ScrollingCoordinatorMac.mm	2022-04-08 18:41:53 UTC (rev 292627)
@@ -68,8 +68,8 @@
     AsyncScrollingCoordinator::pageDestroyed();
 
     // Invalidating the scrolling tree will break the reference cycle between the ScrollingCoordinator and ScrollingTree objects.
-    RefPtr<ThreadedScrollingTree> scrollingTree = static_pointer_cast<ThreadedScrollingTree>(releaseScrollingTree());
-    ScrollingThread::dispatch([scrollingTree] {
+    RefPtr scrollingTree = static_pointer_cast<ThreadedScrollingTree>(releaseScrollingTree());
+    ScrollingThread::dispatch([scrollingTree = WTFMove(scrollingTree)] {
         scrollingTree->invalidate();
     });
 }

Modified: trunk/Source/WebCore/page/scrolling/nicosia/ScrollingCoordinatorNicosia.cpp (292626 => 292627)


--- trunk/Source/WebCore/page/scrolling/nicosia/ScrollingCoordinatorNicosia.cpp	2022-04-08 18:29:35 UTC (rev 292626)
+++ trunk/Source/WebCore/page/scrolling/nicosia/ScrollingCoordinatorNicosia.cpp	2022-04-08 18:41:53 UTC (rev 292627)
@@ -56,8 +56,10 @@
     AsyncScrollingCoordinator::pageDestroyed();
 
     // Invalidating the scrolling tree will break the reference cycle between the ScrollingCoordinator and ScrollingTree objects.
-    RefPtr<ThreadedScrollingTree> scrollingTree = static_pointer_cast<ThreadedScrollingTree>(releaseScrollingTree());
-    ScrollingThread::dispatch([scrollingTree] { scrollingTree->invalidate(); });
+    RefPtr scrollingTree = static_pointer_cast<ThreadedScrollingTree>(releaseScrollingTree());
+    ScrollingThread::dispatch([scrollingTree = WTFMove(scrollingTree)] {
+        scrollingTree->invalidate();
+    });
 }
 
 void ScrollingCoordinatorNicosia::commitTreeStateIfNeeded()
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to