Title: [266573] trunk
Revision
266573
Author
[email protected]
Date
2020-09-03 20:01:34 -0700 (Thu, 03 Sep 2020)

Log Message

Add CompactUniquePtrTuple
https://bugs.webkit.org/show_bug.cgi?id=215936

Reviewed by Darin Adler.

Source/WTF:

Added a new template class, CompactUniquePtrTuple, which stores a pointer and up to 16-bits of
a POD type using CompactPointerTuple.

* WTF.xcodeproj/project.pbxproj:
* wtf/CMakeLists.txt:
* wtf/CompactUniquePtrTuple.h: Added.
(WTF::makeCompactUniquePtr): Added. Like makeUnique, creates an object of the specified type
and returns CompactUniquePtrTuple.
(WTF::CompactUniquePtrTuple): Added.
(WTF::CompactUniquePtrTuple::CompactUniquePtrTuple): Move constructor.
(WTF::CompactUniquePtrTuple::~CompactUniquePtrTuple):
(WTF::CompactUniquePtrTuple::operator=):
(WTF::CompactUniquePtrTuple::pointer):
(WTF::CompactUniquePtrTuple::moveToUniquePtr): Clears this pointer and returns unique_ptr.
(WTF::CompactUniquePtrTuple::setPointer): Like CompactPointerTuple sets the pointer component
of this tuple, freeing the old object if there is already one stored.
(WTF::CompactUniquePtrTuple::type):
(WTF::CompactUniquePtrTuple::setType):
(WTF::CompactUniquePtrTuple::CompactUniquePtrTuple): Constructor which takes unique_ptr&&.
(WTF::CompactUniquePtrTuple::deletePointer):

Tools:

Added basic unit tests for CompactUniquePtrTuple.

* TestWebKitAPI/CMakeLists.txt:
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WTF/CompactUniquePtrTuple.cpp: Added.
(TestWebKitAPI::A): Adde.
(TestWebKitAPI::A::A):
(TestWebKitAPI::A::~A):
(WTF_CompactUniquePtrTuple.Basic):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (266572 => 266573)


--- trunk/Source/WTF/ChangeLog	2020-09-04 02:33:25 UTC (rev 266572)
+++ trunk/Source/WTF/ChangeLog	2020-09-04 03:01:34 UTC (rev 266573)
@@ -1,5 +1,33 @@
 2020-09-02  Ryosuke Niwa  <[email protected]>
 
+        Add CompactUniquePtrTuple
+        https://bugs.webkit.org/show_bug.cgi?id=215936
+
+        Reviewed by Darin Adler.
+
+        Added a new template class, CompactUniquePtrTuple, which stores a pointer and up to 16-bits of
+        a POD type using CompactPointerTuple.
+
+        * WTF.xcodeproj/project.pbxproj:
+        * wtf/CMakeLists.txt:
+        * wtf/CompactUniquePtrTuple.h: Added.
+        (WTF::makeCompactUniquePtr): Added. Like makeUnique, creates an object of the specified type
+        and returns CompactUniquePtrTuple.
+        (WTF::CompactUniquePtrTuple): Added.
+        (WTF::CompactUniquePtrTuple::CompactUniquePtrTuple): Move constructor.
+        (WTF::CompactUniquePtrTuple::~CompactUniquePtrTuple):
+        (WTF::CompactUniquePtrTuple::operator=):
+        (WTF::CompactUniquePtrTuple::pointer):
+        (WTF::CompactUniquePtrTuple::moveToUniquePtr): Clears this pointer and returns unique_ptr.
+        (WTF::CompactUniquePtrTuple::setPointer): Like CompactPointerTuple sets the pointer component
+        of this tuple, freeing the old object if there is already one stored.
+        (WTF::CompactUniquePtrTuple::type):
+        (WTF::CompactUniquePtrTuple::setType):
+        (WTF::CompactUniquePtrTuple::CompactUniquePtrTuple): Constructor which takes unique_ptr&&.
+        (WTF::CompactUniquePtrTuple::deletePointer):
+
+2020-09-02  Ryosuke Niwa  <[email protected]>
+
         Add a variant of map which filters items to Vector.h
         https://bugs.webkit.org/show_bug.cgi?id=215879
 

Modified: trunk/Source/WTF/WTF.xcodeproj/project.pbxproj (266572 => 266573)


--- trunk/Source/WTF/WTF.xcodeproj/project.pbxproj	2020-09-04 02:33:25 UTC (rev 266572)
+++ trunk/Source/WTF/WTF.xcodeproj/project.pbxproj	2020-09-04 03:01:34 UTC (rev 266573)
@@ -496,6 +496,7 @@
 		974CFC8D16A4F327006D5404 /* WeakPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WeakPtr.h; sourceTree = "<group>"; };
 		996B17841EBA441C007E10EB /* DebugUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DebugUtilities.h; sourceTree = "<group>"; };
 		9B67F3F12228D5310030DE9C /* WeakHashSet.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WeakHashSet.h; sourceTree = "<group>"; };
+		9B96E9B324FF77B8001756C3 /* CompactUniquePtrTuple.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CompactUniquePtrTuple.h; sourceTree = "<group>"; };
 		9BC70F04176C379D00101DEC /* AtomStringTable.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AtomStringTable.cpp; sourceTree = "<group>"; };
 		9BD8F40A176C2AD80002D865 /* AtomStringTable.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AtomStringTable.h; sourceTree = "<group>"; };
 		9C67C542589348E285B49699 /* IndexedContainerIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IndexedContainerIterator.h; sourceTree = "<group>"; };
@@ -973,6 +974,7 @@
 				0FC4EDE51696149600F65041 /* CommaPrinter.h */,
 				E3CF76902115D6BA0091DE48 /* CompactPointerTuple.h */,
 				E38020DB2401C0930037CA9E /* CompactRefPtrTuple.h */,
+				9B96E9B324FF77B8001756C3 /* CompactUniquePtrTuple.h */,
 				0F8F2B8F172E00F0007DBDA5 /* CompilationThread.cpp */,
 				0F8F2B90172E00F0007DBDA5 /* CompilationThread.h */,
 				A8A47270151A825A004123FF /* Compiler.h */,

Modified: trunk/Source/WTF/wtf/CMakeLists.txt (266572 => 266573)


--- trunk/Source/WTF/wtf/CMakeLists.txt	2020-09-04 02:33:25 UTC (rev 266572)
+++ trunk/Source/WTF/wtf/CMakeLists.txt	2020-09-04 03:01:34 UTC (rev 266573)
@@ -32,6 +32,7 @@
     CommaPrinter.h
     CompactPointerTuple.h
     CompactRefPtrTuple.h
+    CompactUniquePtrTuple.h
     CompilationThread.h
     Compiler.h
     CompletionHandler.h

Added: trunk/Source/WTF/wtf/CompactUniquePtrTuple.h (0 => 266573)


--- trunk/Source/WTF/wtf/CompactUniquePtrTuple.h	                        (rev 0)
+++ trunk/Source/WTF/wtf/CompactUniquePtrTuple.h	2020-09-04 03:01:34 UTC (rev 266573)
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <memory>
+#include <wtf/CompactPointerTuple.h>
+#include <wtf/Noncopyable.h>
+
+namespace WTF {
+
+template<typename T, typename Type, typename Deleter = std::default_delete<T>> class CompactUniquePtrTuple;
+
+template<typename T, typename Type, typename... Args>
+ALWAYS_INLINE CompactUniquePtrTuple<T, Type> makeCompactUniquePtr(Args&&... args)
+{
+    return CompactUniquePtrTuple<T, Type>(makeUnique<T>(std::forward<Args>(args)...));
+}
+
+template<typename T, typename Type, typename Deleter, typename... Args>
+ALWAYS_INLINE CompactUniquePtrTuple<T, Type> makeCompactUniquePtr(Args&&... args)
+{
+    return CompactUniquePtrTuple<T, Type, Deleter>(makeUnique<T>(std::forward<Args>(args)...));
+}
+
+template<typename T, typename Type, typename Deleter>
+class CompactUniquePtrTuple final {
+    WTF_MAKE_FAST_ALLOCATED;
+    WTF_MAKE_NONCOPYABLE(CompactUniquePtrTuple);
+public:
+    CompactUniquePtrTuple() = default;
+
+    template <typename U>
+    CompactUniquePtrTuple(CompactUniquePtrTuple<U, Type, Deleter>&& other)
+        : m_data { std::exchange(other.m_data, { }) }
+    {
+    }
+
+    ~CompactUniquePtrTuple()
+    {
+        setPointer(nullptr);
+    }
+
+    template <typename U>
+    CompactUniquePtrTuple<T, Type, Deleter>& operator=(CompactUniquePtrTuple<U, Type, Deleter>&& other)
+    {
+        auto moved = WTFMove(other);
+        std::swap(m_data, moved.m_data);
+        return *this;
+    }
+
+    T* pointer() const { return m_data.pointer(); }
+
+    std::unique_ptr<T, Deleter> moveToUniquePtr()
+    {
+        T* pointer = m_data.pointer();
+        m_data.setPointer(nullptr);
+        return std::unique_ptr<T, Deleter>(pointer);
+    }
+
+    void setPointer(nullptr_t)
+    {
+        deletePointer();
+        m_data.setPointer(nullptr);
+    }
+
+    template <typename U>
+    void setPointer(std::unique_ptr<U, Deleter>&& pointer)
+    {
+        deletePointer();
+        m_data.setPointer(pointer.release());
+    }
+
+    Type type() const { return m_data.type(); }
+
+    void setType(Type type)
+    {
+        m_data.setType(type);
+    }
+
+private:
+    CompactUniquePtrTuple(std::unique_ptr<T>&& pointer)
+    {
+        m_data.setPointer(pointer.release());
+    }
+
+    void deletePointer()
+    {
+        if (T* pointer = m_data.pointer())
+            Deleter()(pointer);
+    }
+
+    template<typename U, typename E, typename... Args> friend CompactUniquePtrTuple<U, E> makeCompactUniquePtr(Args&&... args);
+    template<typename U, typename E, typename D, typename... Args> friend CompactUniquePtrTuple<U, E, D> makeCompactUniquePtr(Args&&... args);
+
+    CompactPointerTuple<T*, Type> m_data;
+};
+
+} // namespace WTF
+
+using WTF::CompactUniquePtrTuple;
+using WTF::makeCompactUniquePtr;

Modified: trunk/Tools/ChangeLog (266572 => 266573)


--- trunk/Tools/ChangeLog	2020-09-04 02:33:25 UTC (rev 266572)
+++ trunk/Tools/ChangeLog	2020-09-04 03:01:34 UTC (rev 266573)
@@ -1,3 +1,20 @@
+2020-09-02  Ryosuke Niwa  <[email protected]>
+
+        Add CompactUniquePtrTuple
+        https://bugs.webkit.org/show_bug.cgi?id=215936
+
+        Reviewed by Darin Adler.
+
+        Added basic unit tests for CompactUniquePtrTuple.
+
+        * TestWebKitAPI/CMakeLists.txt:
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WTF/CompactUniquePtrTuple.cpp: Added.
+        (TestWebKitAPI::A): Adde.
+        (TestWebKitAPI::A::A):
+        (TestWebKitAPI::A::~A):
+        (WTF_CompactUniquePtrTuple.Basic):
+
 2020-09-03  Lauro Moura  <[email protected]>
 
         [GTK][WPE] generate-bundle: Remove the zip extension from the uploaded checksum filename

Modified: trunk/Tools/TestWebKitAPI/CMakeLists.txt (266572 => 266573)


--- trunk/Tools/TestWebKitAPI/CMakeLists.txt	2020-09-04 02:33:25 UTC (rev 266572)
+++ trunk/Tools/TestWebKitAPI/CMakeLists.txt	2020-09-04 03:01:34 UTC (rev 266573)
@@ -33,6 +33,7 @@
     Tests/WTF/CString.cpp
     Tests/WTF/CheckedArithmeticOperations.cpp
     Tests/WTF/CompactRefPtrTuple.cpp
+    Tests/WTF/CompactUniquePtrTuple.cpp
     Tests/WTF/ConcurrentPtrHashSet.cpp
     Tests/WTF/Condition.cpp
     Tests/WTF/CrossThreadCopier.cpp

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (266572 => 266573)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2020-09-04 02:33:25 UTC (rev 266572)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2020-09-04 03:01:34 UTC (rev 266573)
@@ -830,6 +830,7 @@
 		9999108B1F393C96008AD455 /* Copying.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9999108A1F393C8B008AD455 /* Copying.mm */; };
 		9B02E0D6235FA47D004044B2 /* TextManipulation.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9B02E0D5235FA47D004044B2 /* TextManipulation.mm */; };
 		9B0786A51C5885C300D159E3 /* InjectedBundleMakeAllShadowRootsOpen_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9B0786A41C5885C300D159E3 /* InjectedBundleMakeAllShadowRootsOpen_Bundle.cpp */; };
+		9B0C051924FDFB7D00F2FE31 /* CompactUniquePtrTuple.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9B0C051824FDFB7000F2FE31 /* CompactUniquePtrTuple.cpp */; };
 		9B19CDA01F06DFE3000548DD /* NetworkProcessCrashWithPendingConnection.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9B19CD9E1F06DFE3000548DD /* NetworkProcessCrashWithPendingConnection.mm */; };
 		9B1F6F781F90558400B55744 /* CopyHTML.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9B1056411F9045C700D5583F /* CopyHTML.mm */; };
 		9B1F6F791F90559E00B55744 /* copy-html.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9B1056421F9047CC00D5583F /* copy-html.html */; };
@@ -2427,6 +2428,7 @@
 		9B02E0D5235FA47D004044B2 /* TextManipulation.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = TextManipulation.mm; sourceTree = "<group>"; };
 		9B0786A21C58830F00D159E3 /* InjectedBundleMakeAllShadowRootsOpen.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InjectedBundleMakeAllShadowRootsOpen.cpp; sourceTree = "<group>"; };
 		9B0786A41C5885C300D159E3 /* InjectedBundleMakeAllShadowRootsOpen_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InjectedBundleMakeAllShadowRootsOpen_Bundle.cpp; sourceTree = "<group>"; };
+		9B0C051824FDFB7000F2FE31 /* CompactUniquePtrTuple.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CompactUniquePtrTuple.cpp; sourceTree = "<group>"; };
 		9B1056411F9045C700D5583F /* CopyHTML.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = CopyHTML.mm; sourceTree = "<group>"; };
 		9B1056421F9047CC00D5583F /* copy-html.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "copy-html.html"; sourceTree = "<group>"; };
 		9B19CD9E1F06DFE3000548DD /* NetworkProcessCrashWithPendingConnection.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = NetworkProcessCrashWithPendingConnection.mm; path = WebKit/NetworkProcessCrashWithPendingConnection.mm; sourceTree = "<group>"; };
@@ -4134,6 +4136,7 @@
 				0451A5A6235E438E009DF945 /* BumpPointerAllocator.cpp */,
 				A7A966DA140ECCC8005EF9B4 /* CheckedArithmeticOperations.cpp */,
 				E302BDA92404B92300865277 /* CompactRefPtrTuple.cpp */,
+				9B0C051824FDFB7000F2FE31 /* CompactUniquePtrTuple.cpp */,
 				0F30CB5B1FCE1792004B5323 /* ConcurrentPtrHashSet.cpp */,
 				0FEAE3671B7D19CB00CE17F2 /* Condition.cpp */,
 				278DE64B22B8D611004E0E7A /* CrossThreadCopier.cpp */,
@@ -4866,6 +4869,7 @@
 				04DB2396235E43EC00328F17 /* BumpPointerAllocator.cpp in Sources */,
 				7C83DEA01D0A590C00FEBCF3 /* CheckedArithmeticOperations.cpp in Sources */,
 				E302BDAA2404B92400865277 /* CompactRefPtrTuple.cpp in Sources */,
+				9B0C051924FDFB7D00F2FE31 /* CompactUniquePtrTuple.cpp in Sources */,
 				0F30CB5C1FCE1796004B5323 /* ConcurrentPtrHashSet.cpp in Sources */,
 				7C83DEC31D0A590C00FEBCF3 /* Condition.cpp in Sources */,
 				7C83DEA61D0A590C00FEBCF3 /* Counters.cpp in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/WTF/CompactUniquePtrTuple.cpp (0 => 266573)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/CompactUniquePtrTuple.cpp	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/CompactUniquePtrTuple.cpp	2020-09-04 03:01:34 UTC (rev 266573)
@@ -0,0 +1,152 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "RefLogger.h"
+#include "Utilities.h"
+#include <wtf/CompactUniquePtrTuple.h>
+#include <wtf/RefCounted.h>
+#include <wtf/RefPtr.h>
+
+namespace TestWebKitAPI {
+
+class A {
+    WTF_MAKE_FAST_ALLOCATED;
+
+public:
+    A() { ++s_constructorCallCount; }
+    ~A() { ++s_destructorCallCount; }
+    
+    static unsigned s_constructorCallCount;
+    static unsigned s_destructorCallCount;
+};
+
+unsigned A::s_constructorCallCount = 0;
+unsigned A::s_destructorCallCount = 0;
+
+TEST(WTF_CompactUniquePtrTuple, Basic)
+{
+    A::s_constructorCallCount = 0;
+    A::s_destructorCallCount = 0;
+
+    CompactUniquePtrTuple<A, uint16_t> empty;
+    EXPECT_EQ(0U, A::s_constructorCallCount);
+    EXPECT_EQ(0U, A::s_destructorCallCount);
+    EXPECT_EQ(nullptr, empty.pointer());
+    EXPECT_EQ(0U, empty.type());
+
+    CompactUniquePtrTuple<A, uint16_t> a = makeCompactUniquePtr<A, uint16_t>();
+    EXPECT_EQ(1U, A::s_constructorCallCount);
+    EXPECT_EQ(0U, A::s_destructorCallCount);
+    EXPECT_NE(nullptr, a.pointer());
+    EXPECT_EQ(0U, a.type());
+
+    a.setPointer(nullptr);
+    EXPECT_EQ(1U, A::s_constructorCallCount);
+    EXPECT_EQ(1U, A::s_destructorCallCount);
+    EXPECT_EQ(nullptr, a.pointer());
+    EXPECT_EQ(0U, a.type());
+
+    a = makeCompactUniquePtr<A, uint16_t>();
+    EXPECT_EQ(2U, A::s_constructorCallCount);
+    EXPECT_EQ(1U, A::s_destructorCallCount);
+    EXPECT_NE(nullptr, a.pointer());
+    EXPECT_EQ(0U, a.type());
+
+    a.setType(0xffffU);
+    EXPECT_EQ(2U, A::s_constructorCallCount);
+    EXPECT_EQ(1U, A::s_destructorCallCount);
+    EXPECT_NE(nullptr, a.pointer());
+    EXPECT_EQ(0xffffU, a.type());
+
+    a.setPointer(makeUnique<A>());
+    A* oldPointer = a.pointer();
+    EXPECT_EQ(3U, A::s_constructorCallCount);
+    EXPECT_EQ(2U, A::s_destructorCallCount);
+    EXPECT_NE(nullptr, a.pointer());
+    EXPECT_EQ(0xffffU, a.type());
+
+    a.setType(0x1010U);
+    EXPECT_EQ(3U, A::s_constructorCallCount);
+    EXPECT_EQ(2U, A::s_destructorCallCount);
+    EXPECT_EQ(oldPointer, a.pointer());
+    EXPECT_EQ(0x1010U, a.type());
+
+    a = makeCompactUniquePtr<A, uint16_t>();
+    EXPECT_EQ(4U, A::s_constructorCallCount);
+    EXPECT_EQ(3U, A::s_destructorCallCount);
+    EXPECT_NE(nullptr, a.pointer());
+    EXPECT_EQ(0x0U, a.type());
+
+    a.setType(0xf2f2U);
+    EXPECT_EQ(4U, A::s_constructorCallCount);
+    EXPECT_EQ(3U, A::s_destructorCallCount);
+    EXPECT_NE(nullptr, a.pointer());
+    EXPECT_EQ(0xf2f2U, a.type());
+
+    oldPointer = a.pointer();
+    auto movedA = a.moveToUniquePtr();
+    EXPECT_EQ(4U, A::s_constructorCallCount);
+    EXPECT_EQ(3U, A::s_destructorCallCount);
+    EXPECT_EQ(nullptr, a.pointer());
+    EXPECT_EQ(movedA.get(), oldPointer);
+    EXPECT_EQ(0xf2f2U, a.type());
+
+    a.setPointer(WTFMove(movedA));
+    EXPECT_EQ(4U, A::s_constructorCallCount);
+    EXPECT_EQ(3U, A::s_destructorCallCount);
+    EXPECT_EQ(oldPointer, a.pointer());
+    EXPECT_EQ(movedA.get(), nullptr);
+    EXPECT_EQ(0xf2f2U, a.type());
+
+    CompactUniquePtrTuple<A, uint16_t> b = WTFMove(a);
+    EXPECT_EQ(4U, A::s_constructorCallCount);
+    EXPECT_EQ(3U, A::s_destructorCallCount);
+    EXPECT_EQ(nullptr, a.pointer());
+    EXPECT_EQ(0, a.type());
+    EXPECT_EQ(oldPointer, b.pointer());
+    EXPECT_EQ(0xf2f2U, b.type());
+
+    CompactUniquePtrTuple<A, uint16_t>* bPtr = &b;
+
+    b = WTFMove(*bPtr);
+    EXPECT_EQ(4U, A::s_constructorCallCount);
+    EXPECT_EQ(3U, A::s_destructorCallCount);
+    EXPECT_EQ(nullptr, a.pointer());
+    EXPECT_EQ(0, a.type());
+    EXPECT_EQ(oldPointer, b.pointer());
+    EXPECT_EQ(0xf2f2U, b.type());
+
+    b.setPointer(nullptr);
+    EXPECT_EQ(4U, A::s_constructorCallCount);
+    EXPECT_EQ(4U, A::s_destructorCallCount);
+    EXPECT_EQ(nullptr, a.pointer());
+    EXPECT_EQ(0, a.type());
+    EXPECT_EQ(nullptr, b.pointer());
+    EXPECT_EQ(0xf2f2U, b.type());
+}
+
+} // namespace TestWebKitAPI
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to