⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 246623 in webkit


Ignore:
Timestamp:
Jun 19, 2019, 5:51:30 PM (7 years ago)
Author:
Fujii Hironori
Message:

Add WTF::crossThreadCopy(T&&) to utilize String::isolatedCopy() &&
https://bugs.webkit.org/show_bug.cgi?id=198957

Reviewed by Alex Christensen.

Source/WTF:

&&-qualified String::isolatedCopy() has a optimization path which
does just WTFMove if it isSafeToSendToAnotherThread which means
the object hasOneRef.

However, WTF::crossThreadCopy was using only &-qualified
isolatedCopy. To use the optimization, added
WTF::crossThreadCopy(T&&) overloading.

  • wtf/CrossThreadCopier.h:

(WTF::crossThreadCopy): Added a overload of (T&&).

  • wtf/CrossThreadTask.h:

(WTF::createCrossThreadTask): Removed explicit template arguments of crossThreadCopy.

Tools:

  • TestWebKitAPI/CMakeLists.txt:
  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WTF/CrossThreadCopier.cpp: Added.
Location:
trunk
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r246616 r246623  
     12019-06-19  Fujii Hironori  <Hironori.Fujii@sony.com>
     2
     3        Add WTF::crossThreadCopy(T&&) to utilize String::isolatedCopy() &&
     4        https://bugs.webkit.org/show_bug.cgi?id=198957
     5
     6        Reviewed by Alex Christensen.
     7
     8        &&-qualified String::isolatedCopy() has a optimization path which
     9        does just WTFMove if it isSafeToSendToAnotherThread which means
     10        the object hasOneRef.
     11
     12        However, WTF::crossThreadCopy was using only &-qualified
     13        isolatedCopy. To use the optimization, added
     14        WTF::crossThreadCopy(T&&) overloading.
     15
     16        * wtf/CrossThreadCopier.h:
     17        (WTF::crossThreadCopy): Added a overload of (T&&).
     18        * wtf/CrossThreadTask.h:
     19        (WTF::createCrossThreadTask): Removed explicit template arguments of crossThreadCopy.
     20
    1212019-06-19  Devin Rousso  <drousso@apple.com>
    222
  • trunk/Source/WTF/wtf/CrossThreadCopier.h

    r239427 r246623  
    3232#pragma once
    3333
     34#include <type_traits>
    3435#include <wtf/Assertions.h>
    3536#include <wtf/Forward.h>
     
    7879// Classes that have an isolatedCopy() method get a default specialization.
    7980template<class T> struct CrossThreadCopierBase<false, false, T> {
    80     static T copy(const T& value)
     81    template<typename U> static auto copy(U&& value)
    8182    {
    82         return value.isolatedCopy();
     83        return std::forward<U>(value).isolatedCopy();
    8384    }
    8485};
     
    147148// Default specialization for Optional of CrossThreadCopyable class.
    148149template<typename T> struct CrossThreadCopierBase<false, false, Optional<T>> {
    149     typedef Optional<T> Type;
    150     static Type copy(const Type& source)
     150    template<typename U> static Optional<T> copy(U&& source)
    151151    {
    152152        if (!source)
    153153            return WTF::nullopt;
    154         return CrossThreadCopier<T>::copy(*source);
     154        return CrossThreadCopier<T>::copy(std::forward<U>(source).value());
    155155    }
    156156};
    157157
    158 template<typename T> T crossThreadCopy(const T& source)
     158template<typename T> auto crossThreadCopy(T&& source)
    159159{
    160     return CrossThreadCopier<T>::copy(source);
     160    return CrossThreadCopier<std::remove_cv_t<std::remove_reference_t<T>>>::copy(std::forward<T>(source));
    161161}
    162162   
  • trunk/Source/WTF/wtf/CrossThreadTask.h

    r242732 r246623  
    6868CrossThreadTask createCrossThreadTask(void (*method)(Parameters...), const Arguments&... arguments)
    6969{
    70     return CrossThreadTask([method, arguments = std::make_tuple(crossThreadCopy<Arguments>(arguments)...)]() mutable {
     70    return CrossThreadTask([method, arguments = std::make_tuple(crossThreadCopy(arguments)...)]() mutable {
    7171        callFunctionForCrossThreadTask(method, WTFMove(arguments));
    7272    });
     
    8888CrossThreadTask createCrossThreadTask(T& callee, void (T::*method)(Parameters...), const Arguments&... arguments)
    8989{
    90     return CrossThreadTask([callee = makeRefPtr(&callee), method, arguments = std::make_tuple(crossThreadCopy<Arguments>(arguments)...)]() mutable {
     90    return CrossThreadTask([callee = makeRefPtr(&callee), method, arguments = std::make_tuple(crossThreadCopy(arguments)...)]() mutable {
    9191        callMemberFunctionForCrossThreadTask(callee.get(), method, WTFMove(arguments));
    9292    });
     
    9696CrossThreadTask createCrossThreadTask(T& callee, void (T::*method)(Parameters...), const Arguments&... arguments)
    9797{
    98     return CrossThreadTask([callee = &callee, method, arguments = std::make_tuple(crossThreadCopy<Arguments>(arguments)...)]() mutable {
     98    return CrossThreadTask([callee = &callee, method, arguments = std::make_tuple(crossThreadCopy(arguments)...)]() mutable {
    9999        callMemberFunctionForCrossThreadTask(callee, method, WTFMove(arguments));
    100100    });
  • trunk/Tools/ChangeLog

    r246617 r246623  
     12019-06-19  Fujii Hironori  <Hironori.Fujii@sony.com>
     2
     3        Add WTF::crossThreadCopy(T&&) to utilize String::isolatedCopy() &&
     4        https://bugs.webkit.org/show_bug.cgi?id=198957
     5
     6        Reviewed by Alex Christensen.
     7
     8        * TestWebKitAPI/CMakeLists.txt:
     9        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     10        * TestWebKitAPI/Tests/WTF/CrossThreadCopier.cpp: Added.
     11
    1122019-06-19  Keith Rollin  <krollin@apple.com>
    213
  • trunk/Tools/TestWebKitAPI/CMakeLists.txt

    r246490 r246623  
    3131    Tests/WTF/ConcurrentPtrHashSet.cpp
    3232    Tests/WTF/Condition.cpp
     33    Tests/WTF/CrossThreadCopier.cpp
    3334    Tests/WTF/CrossThreadTask.cpp
    3435    Tests/WTF/DateMath.cpp
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r246578 r246623  
    14711471                26F52EB118288F0F0023D412 /* geolocationWatchPositionWithHighAccuracy.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = geolocationWatchPositionWithHighAccuracy.html; sourceTree = "<group>"; };
    14721472                26F6E1EF1ADC749B00DE696B /* DFAMinimizer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DFAMinimizer.cpp; sourceTree = "<group>"; };
     1473                278DE64B22B8D611004E0E7A /* CrossThreadCopier.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CrossThreadCopier.cpp; sourceTree = "<group>"; };
    14731474                290A9BB51735DE8A00D71BBC /* CloseNewWindowInNavigationPolicyDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CloseNewWindowInNavigationPolicyDelegate.mm; sourceTree = "<group>"; };
    14741475                290A9BB81735F42300D71BBC /* OpenNewWindow.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = OpenNewWindow.html; sourceTree = "<group>"; };
     
    34003401                                0F30CB5B1FCE1792004B5323 /* ConcurrentPtrHashSet.cpp */,
    34013402                                0FEAE3671B7D19CB00CE17F2 /* Condition.cpp */,
     3403                                278DE64B22B8D611004E0E7A /* CrossThreadCopier.cpp */,
    34023404                                51714EB91D087416004723C4 /* CrossThreadTask.cpp */,
    34033405                                26A2C72E15E2E73C005B1A14 /* CString.cpp */,
Note: See TracChangeset for help on using the changeset viewer.