WebKit Bugzilla
Attachment 372330 Details for
Bug 198957
: Add WTF::crossThreadCopy(T&&) to utilize String::isolatedCopy() &&
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
WIP patch
wip.diff (text/plain), 4.76 KB, created by
Fujii Hironori
on 2019-06-18 00:29:37 PDT
(
hide
)
Description:
WIP patch
Filename:
MIME Type:
Creator:
Fujii Hironori
Created:
2019-06-18 00:29:37 PDT
Size:
4.76 KB
patch
obsolete
>diff --git a/Source/WTF/wtf/CrossThreadCopier.h b/Source/WTF/wtf/CrossThreadCopier.h >index 633878ae938..c53373a8607 100644 >--- a/Source/WTF/wtf/CrossThreadCopier.h >+++ b/Source/WTF/wtf/CrossThreadCopier.h >@@ -31,6 +31,7 @@ > > #pragma once > >+#include <type_traits> > #include <wtf/Assertions.h> > #include <wtf/Forward.h> > #include <wtf/HashSet.h> >@@ -77,9 +78,9 @@ template<typename T> struct CrossThreadCopierBase<true, false, T> : public Cross > > // Classes that have an isolatedCopy() method get a default specialization. > template<class T> struct CrossThreadCopierBase<false, false, T> { >- static T copy(const T& value) >+ template<typename U> static auto copy(U&& value) > { >- return value.isolatedCopy(); >+ return std::forward<U>(value).isolatedCopy(); > } > }; > >@@ -153,12 +154,24 @@ template<typename T> struct CrossThreadCopierBase<false, false, Optional<T>> { > return WTF::nullopt; > return CrossThreadCopier<T>::copy(*source); > } >+ >+ static Type copy(Type&& source) >+ { >+ if (!source) >+ return WTF::nullopt; >+ return CrossThreadCopier<T>::copy(WTFMove(*source)); >+ } > }; > > template<typename T> T crossThreadCopy(const T& source) > { > return CrossThreadCopier<T>::copy(source); > } >+ >+template<typename T> auto crossThreadCopy(T&& source) >+{ >+ return CrossThreadCopier<std::remove_reference_t<T>>::copy(std::forward<T>(source)); >+} > > } // namespace WTF > >diff --git a/Tools/TestWebKitAPI/CMakeLists.txt b/Tools/TestWebKitAPI/CMakeLists.txt >index 7adb608eeaa..619e78d39fd 100644 >--- a/Tools/TestWebKitAPI/CMakeLists.txt >+++ b/Tools/TestWebKitAPI/CMakeLists.txt >@@ -30,6 +30,7 @@ set(TestWTF_SOURCES > Tests/WTF/CheckedArithmeticOperations.cpp > Tests/WTF/ConcurrentPtrHashSet.cpp > Tests/WTF/Condition.cpp >+ Tests/WTF/CrossThreadCopier.cpp > Tests/WTF/CrossThreadTask.cpp > Tests/WTF/DateMath.cpp > Tests/WTF/Deque.cpp >diff --git a/Tools/TestWebKitAPI/Tests/WTF/CrossThreadCopier.cpp b/Tools/TestWebKitAPI/Tests/WTF/CrossThreadCopier.cpp >new file mode 100644 >index 00000000000..b6c2b368cd5 >--- /dev/null >+++ b/Tools/TestWebKitAPI/Tests/WTF/CrossThreadCopier.cpp >@@ -0,0 +1,72 @@ >+/* >+ * Copyright (C) 2019 Sony Interactive Entertainment Inc. >+ * >+ * 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 <wtf/CrossThreadCopier.h> >+#include <wtf/Optional.h> >+#include <wtf/text/WTFString.h> >+ >+namespace TestWebKitAPI { >+ >+TEST(WTF_CrossThreadCopier, CopyString) >+{ >+ String original = "1234"; >+ auto copy = crossThreadCopy(original); >+ EXPECT_TRUE(original.impl()->hasOneRef()); >+ EXPECT_TRUE(copy.impl()->hasOneRef()); >+ EXPECT_FALSE(original.impl() == copy.impl()); >+} >+ >+TEST(WTF_CrossThreadCopier, NotCopyString) >+{ >+ String original = "1234"; >+ auto copy = crossThreadCopy(WTFMove(original)); >+ EXPECT_TRUE(copy.impl()->hasOneRef()); >+ // moved-out RefPtr becomes nullptr >+ EXPECT_EQ(nullptr, original.impl()); >+} >+ >+TEST(WTF_CrossThreadCopier, CopyOptionalString) >+{ >+ Optional<String> original = "1234"; >+ auto copy = crossThreadCopy(original); >+ EXPECT_TRUE(original->impl()->hasOneRef()); >+ EXPECT_TRUE(copy->impl()->hasOneRef()); >+ EXPECT_FALSE(original->impl() == copy->impl()); >+} >+ >+TEST(WTF_CrossThreadCopier, NotCopyOptionalString) >+{ >+ Optional<String> original = "1234"; >+ auto copy = crossThreadCopy(WTFMove(original)); >+ EXPECT_TRUE(copy->impl()->hasOneRef()); >+ // moved-out RefPtr becomes nullptr >+ EXPECT_EQ(nullptr, original->impl()); >+} >+ >+ >+ >+} // namespace TestWebKitAPI
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 198957
:
372330
|
372332
|
372422