Title: [293682] trunk/Source/WTF/wtf/Ref.h
- Revision
- 293682
- Author
- cdu...@apple.com
- Date
- 2022-05-02 13:31:54 -0700 (Mon, 02 May 2022)
Log Message
static_reference_cast(const Ref<X, Y>&) causes unnecessary ref-counting churn
https://bugs.webkit.org/show_bug.cgi?id=239970
Reviewed by Geoffrey Garen.
This function was calling copyRef() to get a non-const Ref<> and then calling Ref::get() to construct a
new Ref<> of the destination type. The copyRef() would increase the ref count by 1, constructing the
new destination Ref<> would increase the ref count by 1 again and then the temporary Ref going out of
scope would decrease the ref count by one.
We now call static_reference_cast(Ref<X, Y>&&) with the result of the copyRef(), which will leak
the pointer from the Ref<> and adopt it in the destination Ref, thus avoiding unnecessary churn.
Also drop the static_reference_cast(Ref<X, Y>&) overload as it is no longer more efficient than the
static_reference_cast(const Ref<X, Y>&) one.
* Source/WTF/wtf/Ref.h:
(WTF::static_reference_cast):
Canonical link: https://commits.webkit.org/250182@main
Modified Paths
Diff
Modified: trunk/Source/WTF/wtf/Ref.h (293681 => 293682)
--- trunk/Source/WTF/wtf/Ref.h 2022-05-02 20:29:40 UTC (rev 293681)
+++ trunk/Source/WTF/wtf/Ref.h 2022-05-02 20:31:54 UTC (rev 293682)
@@ -235,12 +235,6 @@
}
template<typename T, typename U = RawPtrTraits<T>, typename X, typename Y>
-inline Ref<T, U> static_reference_cast(Ref<X, Y>& reference)
-{
- return Ref<T, U>(static_cast<T&>(reference.get()));
-}
-
-template<typename T, typename U = RawPtrTraits<T>, typename X, typename Y>
inline Ref<T, U> static_reference_cast(Ref<X, Y>&& reference)
{
return adoptRef(static_cast<T&>(reference.leakRef()));
@@ -247,9 +241,9 @@
}
template<typename T, typename U = RawPtrTraits<T>, typename X, typename Y>
-inline Ref<T, U> static_reference_cast(const Ref<X, Y>& reference)
+ALWAYS_INLINE Ref<T, U> static_reference_cast(const Ref<X, Y>& reference)
{
- return Ref<T, U>(static_cast<T&>(reference.copyRef().get()));
+ return static_reference_cast<T, U>(reference.copyRef());
}
template <typename T, typename U>
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes