Title: [290552] trunk
Revision
290552
Author
[email protected]
Date
2022-02-26 15:36:45 -0800 (Sat, 26 Feb 2022)

Log Message

Drop Ref<>'s operator==() as it is a bit ambiguous / confusing
https://bugs.webkit.org/show_bug.cgi?id=237231

Reviewed by Darin Adler.

Drop Ref<>'s operator==() as it is a bit ambiguous / confusing. Some people expect it to compare
pointers while other expect it to compare the values we hold references to.
It seems best to omit this operator and be explicit at call sites.

Source/WebCore:

* Modules/mediastream/libwebrtc/LibWebRTCRtpSenderBackend.cpp:
(WebCore::LibWebRTCRtpSenderBackend::startSource):
* svg/SVGDocumentExtensions.cpp:
(WebCore::SVGDocumentExtensions::removeElementToRebuild):
* svg/graphics/filters/SVGFilterBuilder.cpp:
(WebCore::SVGFilterBuilder::buildEffectExpression const):

Source/WebKit:

* UIProcess/Cocoa/WebProcessProxyCocoa.mm:
(WebKit::WebProcessProxy::cacheMediaMIMETypes):
* UIProcess/VisitedLinkStore.cpp:
(WebKit::VisitedLinkStore::removeAll):
(WebKit::VisitedLinkStore::sendStoreHandleToProcess):
(WebKit::VisitedLinkStore::didUpdateSharedStringHashes):
* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::shouldTerminate):

Source/WTF:

* wtf/Ref.h:
(WTF::operator==): Deleted.
(WTF::operator!=): Deleted.
* wtf/Vector.h:
(WTF::Vector::containsIf const):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (290551 => 290552)


--- trunk/Source/WTF/ChangeLog	2022-02-26 22:12:25 UTC (rev 290551)
+++ trunk/Source/WTF/ChangeLog	2022-02-26 23:36:45 UTC (rev 290552)
@@ -1,3 +1,20 @@
+2022-02-26  Chris Dumez  <[email protected]>
+
+        Drop Ref<>'s operator==() as it is a bit ambiguous / confusing
+        https://bugs.webkit.org/show_bug.cgi?id=237231
+
+        Reviewed by Darin Adler.
+
+        Drop Ref<>'s operator==() as it is a bit ambiguous / confusing. Some people expect it to compare
+        pointers while other expect it to compare the values we hold references to.
+        It seems best to omit this operator and be explicit at call sites.
+
+        * wtf/Ref.h:
+        (WTF::operator==): Deleted.
+        (WTF::operator!=): Deleted.
+        * wtf/Vector.h:
+        (WTF::Vector::containsIf const):
+
 2022-02-25  Elliott Williams  <[email protected]>
 
         [XCBuild] Add missing header build rule for Scripts/Preferences/*

Modified: trunk/Source/WTF/wtf/Ref.h (290551 => 290552)


--- trunk/Source/WTF/wtf/Ref.h	2022-02-26 22:12:25 UTC (rev 290551)
+++ trunk/Source/WTF/wtf/Ref.h	2022-02-26 23:36:45 UTC (rev 290552)
@@ -282,42 +282,6 @@
     return is<ExpectedType>(source.get());
 }
 
-template<typename T, typename U, typename V, typename W>
-inline bool operator==(const Ref<T, U>& a, const Ref<V, W>& b)
-{
-    return a.ptr() == b.ptr();
-}
-
-template<typename T, typename U, typename V>
-inline bool operator==(const Ref<T, U>& a, V& b)
-{
-    return a.ptr() == &b;
-}
-
-template<typename T, typename U, typename V>
-inline bool operator==(T& a, const Ref<U, V>& b)
-{
-    return &a == b.ptr();
-}
-
-template<typename T, typename U, typename V, typename W>
-inline bool operator!=(const Ref<T, U>& a, const Ref<V, W>& b)
-{
-    return a.ptr() != b.ptr();
-}
-
-template<typename T, typename U, typename V>
-inline bool operator!=(const Ref<T, U>& a, V& b)
-{
-    return a.ptr() != &b;
-}
-
-template<typename T, typename U, typename V>
-inline bool operator!=(T& a, const Ref<U, V>& b)
-{
-    return &a != b.ptr();
-}
-
 } // namespace WTF
 
 using WTF::Ref;

Modified: trunk/Source/WTF/wtf/Vector.h (290551 => 290552)


--- trunk/Source/WTF/wtf/Vector.h	2022-02-26 22:12:25 UTC (rev 290551)
+++ trunk/Source/WTF/wtf/Vector.h	2022-02-26 23:36:45 UTC (rev 290552)
@@ -759,6 +759,7 @@
     template<typename MatchFunction> size_t findIf(const MatchFunction&) const;
     template<typename U> size_t reverseFind(const U&) const;
     template<typename MatchFunction> size_t reverseFindIf(const MatchFunction&) const;
+    template<typename MatchFunction> bool containsIf(const MatchFunction& matches) const { return findIf(matches) != notFound; }
 
     template<typename U> bool appendIfNotContains(const U&);
 

Modified: trunk/Source/WebCore/ChangeLog (290551 => 290552)


--- trunk/Source/WebCore/ChangeLog	2022-02-26 22:12:25 UTC (rev 290551)
+++ trunk/Source/WebCore/ChangeLog	2022-02-26 23:36:45 UTC (rev 290552)
@@ -1,3 +1,21 @@
+2022-02-26  Chris Dumez  <[email protected]>
+
+        Drop Ref<>'s operator==() as it is a bit ambiguous / confusing
+        https://bugs.webkit.org/show_bug.cgi?id=237231
+
+        Reviewed by Darin Adler.
+
+        Drop Ref<>'s operator==() as it is a bit ambiguous / confusing. Some people expect it to compare
+        pointers while other expect it to compare the values we hold references to.
+        It seems best to omit this operator and be explicit at call sites.
+
+        * Modules/mediastream/libwebrtc/LibWebRTCRtpSenderBackend.cpp:
+        (WebCore::LibWebRTCRtpSenderBackend::startSource):
+        * svg/SVGDocumentExtensions.cpp:
+        (WebCore::SVGDocumentExtensions::removeElementToRebuild):
+        * svg/graphics/filters/SVGFilterBuilder.cpp:
+        (WebCore::SVGFilterBuilder::buildEffectExpression const):
+
 2022-02-26  Kate Cheney  <[email protected]>
 
         Update CSP handling of _javascript_ URLs

Modified: trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCRtpSenderBackend.cpp (290551 => 290552)


--- trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCRtpSenderBackend.cpp	2022-02-26 22:12:25 UTC (rev 290551)
+++ trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCRtpSenderBackend.cpp	2022-02-26 23:36:45 UTC (rev 290552)
@@ -62,13 +62,15 @@
 void LibWebRTCRtpSenderBackend::startSource()
 {
     // We asynchronously start the sources to guarantee media goes through the transform if a transform is set when creating the track.
-    callOnMainThread([weakThis = WeakPtr { *this }, source = m_source]() mutable {
-        if (!weakThis || weakThis->m_source != source)
+    callOnMainThread([this, weakThis = WeakPtr { *this }, source = m_source]() mutable {
+        if (!weakThis)
             return;
-        switchOn(source, [](Ref<RealtimeOutgoingAudioSource>& source) {
-            source->start();
-        }, [](Ref<RealtimeOutgoingVideoSource>& source) {
-            source->start();
+        switchOn(source, [this](Ref<RealtimeOutgoingAudioSource>& source) {
+            if (auto* currentSource = std::get_if<Ref<RealtimeOutgoingAudioSource>>(&m_source); currentSource && currentSource->ptr() == source.ptr())
+                source->start();
+        }, [this](Ref<RealtimeOutgoingVideoSource>& source) {
+            if (auto* currentSource = std::get_if<Ref<RealtimeOutgoingVideoSource>>(&m_source); currentSource && currentSource->ptr() == source.ptr())
+                source->start();
         }, [](std::nullptr_t&) {
         });
     });

Modified: trunk/Source/WebCore/svg/SVGDocumentExtensions.cpp (290551 => 290552)


--- trunk/Source/WebCore/svg/SVGDocumentExtensions.cpp	2022-02-26 22:12:25 UTC (rev 290551)
+++ trunk/Source/WebCore/svg/SVGDocumentExtensions.cpp	2022-02-26 23:36:45 UTC (rev 290552)
@@ -277,7 +277,7 @@
 
 void SVGDocumentExtensions::removeElementToRebuild(SVGElement& element)
 {
-    m_rebuildElements.removeFirst(element);
+    m_rebuildElements.removeFirstMatching([&](auto& item) { return item.ptr() == &element; });
 }
 
 void SVGDocumentExtensions::rebuildElements()

Modified: trunk/Source/WebCore/svg/graphics/filters/SVGFilterBuilder.cpp (290551 => 290552)


--- trunk/Source/WebCore/svg/graphics/filters/SVGFilterBuilder.cpp	2022-02-26 22:12:25 UTC (rev 290551)
+++ trunk/Source/WebCore/svg/graphics/filters/SVGFilterBuilder.cpp	2022-02-26 23:36:45 UTC (rev 290552)
@@ -191,7 +191,7 @@
 bool SVGFilterBuilder::buildEffectExpression(FilterEffect& effect, FilterEffectVector& stack, unsigned level, SVGFilterExpression& _expression_) const
 {
     // A cycle is detected.
-    if (stack.contains(effect))
+    if (stack.containsIf([&](auto& item) { return item.ptr() == &effect; }))
         return false;
 
     stack.append(effect);
@@ -204,7 +204,7 @@
     }
 
     ASSERT(!stack.isEmpty());
-    ASSERT(stack.last() == effect);
+    ASSERT(stack.last().ptr() == &effect);
 
     stack.removeLast();
     return true;

Modified: trunk/Source/WebKit/ChangeLog (290551 => 290552)


--- trunk/Source/WebKit/ChangeLog	2022-02-26 22:12:25 UTC (rev 290551)
+++ trunk/Source/WebKit/ChangeLog	2022-02-26 23:36:45 UTC (rev 290552)
@@ -1,3 +1,23 @@
+2022-02-26  Chris Dumez  <[email protected]>
+
+        Drop Ref<>'s operator==() as it is a bit ambiguous / confusing
+        https://bugs.webkit.org/show_bug.cgi?id=237231
+
+        Reviewed by Darin Adler.
+
+        Drop Ref<>'s operator==() as it is a bit ambiguous / confusing. Some people expect it to compare
+        pointers while other expect it to compare the values we hold references to.
+        It seems best to omit this operator and be explicit at call sites.
+
+        * UIProcess/Cocoa/WebProcessProxyCocoa.mm:
+        (WebKit::WebProcessProxy::cacheMediaMIMETypes):
+        * UIProcess/VisitedLinkStore.cpp:
+        (WebKit::VisitedLinkStore::removeAll):
+        (WebKit::VisitedLinkStore::sendStoreHandleToProcess):
+        (WebKit::VisitedLinkStore::didUpdateSharedStringHashes):
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::shouldTerminate):
+
 2022-02-26  Kimmo Kinnunen  <[email protected]>
 
         Multiple concurrency violations in LibWebRTCCodecsProxy

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebProcessProxyCocoa.mm (290551 => 290552)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebProcessProxyCocoa.mm	2022-02-26 22:12:25 UTC (rev 290551)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebProcessProxyCocoa.mm	2022-02-26 23:36:45 UTC (rev 290552)
@@ -169,7 +169,7 @@
 
     mediaTypeCache() = types;
     for (auto& process : processPool().processes()) {
-        if (process != *this)
+        if (process.ptr() != this)
             cacheMediaMIMETypesInternal(types);
     }
 }

Modified: trunk/Source/WebKit/UIProcess/VisitedLinkStore.cpp (290551 => 290552)


--- trunk/Source/WebKit/UIProcess/VisitedLinkStore.cpp	2022-02-26 22:12:25 UTC (rev 290551)
+++ trunk/Source/WebKit/UIProcess/VisitedLinkStore.cpp	2022-02-26 23:36:45 UTC (rev 290552)
@@ -95,7 +95,7 @@
     m_linkHashStore.clear();
 
     for (auto& process : m_processes) {
-        ASSERT(process.processPool().processes().contains(process));
+        ASSERT(process.processPool().processes().containsIf([&](auto& item) { return item.ptr() == &process; }));
         process.send(Messages::VisitedLinkTableController::RemoveAllVisitedLinks(), identifier());
     }
 }
@@ -112,7 +112,7 @@
 
 void VisitedLinkStore::sendStoreHandleToProcess(WebProcessProxy& process)
 {
-    ASSERT(process.processPool().processes().contains(process));
+    ASSERT(process.processPool().processes().containsIf([&](auto& item) { return item.ptr() == &process; }));
 
     SharedMemory::Handle handle;
     if (!m_linkHashStore.createSharedMemoryHandle(handle))
@@ -138,7 +138,7 @@
     ASSERT(!addedHashes.isEmpty() || !removedHashes.isEmpty());
 
     for (auto& process : m_processes) {
-        ASSERT(process.processPool().processes().contains(process));
+        ASSERT(process.processPool().processes().containsIf([&](auto& item) { return item.ptr() == &process; }));
 
         if (addedHashes.size() > 20 || !removedHashes.isEmpty())
             process.send(Messages::VisitedLinkTableController::AllVisitedLinkStateChanged(), identifier());

Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.cpp (290551 => 290552)


--- trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2022-02-26 22:12:25 UTC (rev 290551)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2022-02-26 23:36:45 UTC (rev 290552)
@@ -955,7 +955,7 @@
 
 bool WebProcessPool::shouldTerminate(WebProcessProxy& process)
 {
-    ASSERT(m_processes.contains(process));
+    ASSERT(m_processes.containsIf([&](auto& item) { return item.ptr() == &process; }));
 
     if (!m_processTerminationEnabled || m_configuration->alwaysKeepAndReuseSwappedProcesses())
         return false;
@@ -965,7 +965,7 @@
 
 void WebProcessPool::processDidFinishLaunching(WebProcessProxy& process)
 {
-    ASSERT(m_processes.contains(process));
+    ASSERT(m_processes.containsIf([&](auto& item) { return item.ptr() == &process; }));
 
     if (!m_visitedLinksPopulated) {
         populateVisitedLinks();
@@ -997,7 +997,7 @@
 
 void WebProcessPool::disconnectProcess(WebProcessProxy& process)
 {
-    ASSERT(m_processes.contains(process));
+    ASSERT(m_processes.containsIf([&](auto& item) { return item.ptr() == &process; }));
 
     if (m_prewarmedProcess == &process) {
         ASSERT(m_prewarmedProcess->isPrewarmed());
@@ -1018,7 +1018,7 @@
 
     supplement<WebGeolocationManagerProxy>()->webProcessIsGoingAway(process);
 
-    m_processes.removeFirst(process);
+    m_processes.removeFirstMatching([&](auto& item) { return item.ptr() == &process; });
 
 #if ENABLE(GAMEPAD)
     if (m_processesUsingGamepads.contains(process))
@@ -1032,7 +1032,7 @@
 {
     if (!registrableDomain.isEmpty()) {
         if (auto process = webProcessCache().takeProcess(registrableDomain, websiteDataStore, captivePortalMode)) {
-            ASSERT(m_processes.contains(*process));
+            ASSERT(m_processes.containsIf([&](auto& item) { return item.ptr() == process; }));
             return process.releaseNonNull();
         }
 
@@ -1039,7 +1039,7 @@
         // Check if we have a suspended page for the given registrable domain and use its process if we do, for performance reasons.
         if (auto process = SuspendedPageProxy::findReusableSuspendedPageProcess(*this, registrableDomain, websiteDataStore, captivePortalMode)) {
             WEBPROCESSPOOL_RELEASE_LOG(ProcessSwapping, "processForRegistrableDomain: Using WebProcess from a SuspendedPage (process=%p, PID=%i)", process.get(), process->processIdentifier());
-            ASSERT(m_processes.contains(*process));
+            ASSERT(m_processes.containsIf([&](auto& item) { return item.ptr() == process; }));
             return process.releaseNonNull();
         }
     }
@@ -1048,7 +1048,7 @@
         WEBPROCESSPOOL_RELEASE_LOG(ProcessSwapping, "processForRegistrableDomain: Using prewarmed process (process=%p, PID=%i)", process.get(), process->processIdentifier());
         if (!registrableDomain.isEmpty())
             tryPrewarmWithDomainInformation(*process, registrableDomain);
-        ASSERT(m_processes.contains(*process));
+        ASSERT(m_processes.containsIf([&](auto& item) { return item.ptr() == process; }));
         return process.releaseNonNull();
     }
 

Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/WeakPtr.cpp (290551 => 290552)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/WeakPtr.cpp	2022-02-26 22:12:25 UTC (rev 290551)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/WeakPtr.cpp	2022-02-26 23:36:45 UTC (rev 290552)
@@ -1608,7 +1608,7 @@
     }
 
     {
-        WeakHashMap<Base, Ref<ValueObject>> weakHashMap;
+        WeakHashMap<Base, RefPtr<ValueObject>> weakHashMap;
         {
             Vector<std::pair<std::unique_ptr<Base>, RefPtr<ValueObject>>> objects;
             for (unsigned i = 0; i < 50; ++i) {
@@ -1618,7 +1618,7 @@
                     objects.append(std::pair { makeUnique<Base>(), ValueObject::create(i) });
                 objects.last().first->dummy = 0;
                 if (i < 25)
-                    weakHashMap.add(*objects.last().first, *objects.last().second);
+                    weakHashMap.add(*objects.last().first, objects.last().second);
             }
             weakHashMap.checkConsistency();
             EXPECT_EQ(s_baseWeakReferences, 25u);
@@ -1704,7 +1704,7 @@
         }
         EXPECT_EQ(s_baseWeakReferences, 16u);
         EXPECT_TRUE(weakHashMap.hasNullReferences());
-        auto pairs = collectKeyValuePairsUsingIterators<Base*, Ref<ValueObject>>(weakHashMap);
+        auto pairs = collectKeyValuePairsUsingIterators<Base*, RefPtr<ValueObject>>(weakHashMap);
         EXPECT_EQ(pairs.size(), 0U);
         weakHashMap.removeNullReferences();
         EXPECT_FALSE(weakHashMap.hasNullReferences());
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to