Changeset 252870 in webkit


Ignore:
Timestamp:
Nov 25, 2019 5:55:32 PM (4 years ago)
Author:
Fujii Hironori
Message:

Add DefaultHash<OptionSet<T>> and HashTrait<OptionSet<T>> specializations
https://bugs.webkit.org/show_bug.cgi?id=204562

Reviewed by Daniel Bates.

Source/WTF:

  • WTF.xcodeproj/project.pbxproj: Added OptionSetHash.h
  • wtf/CMakeLists.txt: Ditto.
  • wtf/OptionSet.h: Made StorageType public, and use C++14 types.
  • wtf/OptionSetHash.h: Added.

(WTF::DefaultHash<OptionSet<T>>::Hash::hash):
(WTF::DefaultHash<OptionSet<T>>::Hash::equal):
(WTF::HashTraits<OptionSet<T>>::emptyValue):
(WTF::HashTraits<OptionSet<T>>::constructDeletedValue):
(WTF::HashTraits<OptionSet<T>>::isDeletedValue):

Tools:

  • TestWebKitAPI/Tests/WTF/OptionSet.cpp:

Added a new test WTF_OptionSet.HashSet.

Location:
trunk
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r252855 r252870  
     12019-11-25  Fujii Hironori  <Hironori.Fujii@sony.com>
     2
     3        Add DefaultHash<OptionSet<T>> and HashTrait<OptionSet<T>> specializations
     4        https://bugs.webkit.org/show_bug.cgi?id=204562
     5
     6        Reviewed by Daniel Bates.
     7
     8        * WTF.xcodeproj/project.pbxproj: Added OptionSetHash.h
     9        * wtf/CMakeLists.txt: Ditto.
     10        * wtf/OptionSet.h: Made StorageType public, and use C++14 types.
     11        * wtf/OptionSetHash.h: Added.
     12        (WTF::DefaultHash<OptionSet<T>>::Hash::hash):
     13        (WTF::DefaultHash<OptionSet<T>>::Hash::equal):
     14        (WTF::HashTraits<OptionSet<T>>::emptyValue):
     15        (WTF::HashTraits<OptionSet<T>>::constructDeletedValue):
     16        (WTF::HashTraits<OptionSet<T>>::isDeletedValue):
     17
    1182019-11-25  Carlos Garcia Campos  <cgarcia@igalia.com>
    219
  • trunk/Source/WTF/WTF.xcodeproj/project.pbxproj

    r252850 r252870  
    331331                26299B6D17A9E5B800ADEBE5 /* Ref.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Ref.h; sourceTree = "<group>"; };
    332332                2684D4351C000D400081D663 /* IndexSparseSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IndexSparseSet.h; sourceTree = "<group>"; };
     333                275DFB6B238BDF72001230E2 /* OptionSetHash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OptionSetHash.h; sourceTree = "<group>"; };
    333334                2C05385315BC819000F21B96 /* GregorianDateTime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GregorianDateTime.h; sourceTree = "<group>"; };
    334335                2CCD892915C0390200285083 /* GregorianDateTime.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GregorianDateTime.cpp; sourceTree = "<group>"; };
     
    10701071                                1AFDE6521953B23D00C48FFA /* Optional.h */,
    10711072                                1A4656181C7FC68E00F5920F /* OptionSet.h */,
     1073                                275DFB6B238BDF72001230E2 /* OptionSetHash.h */,
    10721074                                0F9495831C571CC900413A48 /* OrderMaker.h */,
    10731075                                A8A472D7151A825B004123FF /* OSAllocator.h */,
  • trunk/Source/WTF/wtf/CMakeLists.txt

    r252239 r252870  
    152152    ObjectIdentifier.h
    153153    OptionSet.h
     154    OptionSetHash.h
    154155    Optional.h
    155156    OrderMaker.h
  • trunk/Source/WTF/wtf/OptionSet.h

    r248546 r252870  
    4040    WTF_MAKE_FAST_ALLOCATED;
    4141    static_assert(std::is_enum<T>::value, "T is not an enum type");
    42     typedef typename std::make_unsigned<typename std::underlying_type<T>::type>::type StorageType;
    4342
    4443public:
     44    using StorageType = std::make_unsigned_t<std::underlying_type_t<T>>;
     45
    4546    template<typename StorageType> class Iterator {
    4647        WTF_MAKE_FAST_ALLOCATED;
  • trunk/Tools/ChangeLog

    r252860 r252870  
     12019-11-25  Fujii Hironori  <Hironori.Fujii@sony.com>
     2
     3        Add DefaultHash<OptionSet<T>> and HashTrait<OptionSet<T>> specializations
     4        https://bugs.webkit.org/show_bug.cgi?id=204562
     5
     6        Reviewed by Daniel Bates.
     7
     8        * TestWebKitAPI/Tests/WTF/OptionSet.cpp:
     9        Added a new test WTF_OptionSet.HashSet.
     10
    1112019-11-25  Philippe Normand  <pnormand@igalia.com>
    212
  • trunk/Tools/TestWebKitAPI/Tests/WTF/OptionSet.cpp

    r235560 r252870  
    2727
    2828#include "Test.h"
     29#include <wtf/HashSet.h>
    2930#include <wtf/OptionSet.h>
     31#include <wtf/OptionSetHash.h>
    3032
    3133namespace TestWebKitAPI {
     
    437439}
    438440
     441TEST(WTF_OptionSet, HashSet)
     442{
     443    HashSet<OptionSet<ExampleFlags>> hashSet;
     444    EXPECT_TRUE(hashSet.add(OptionSet<ExampleFlags>()).isNewEntry);
     445    EXPECT_TRUE(hashSet.add({ ExampleFlags::A }).isNewEntry);
     446    EXPECT_TRUE(hashSet.add({ ExampleFlags::A, ExampleFlags::B }).isNewEntry);
     447    EXPECT_FALSE(hashSet.add(OptionSet<ExampleFlags>()).isNewEntry);
     448    EXPECT_FALSE(hashSet.add({ ExampleFlags::A }).isNewEntry);
     449    EXPECT_FALSE(hashSet.add({ ExampleFlags::A, ExampleFlags::B }).isNewEntry);
     450    EXPECT_TRUE(hashSet.remove(OptionSet<ExampleFlags>()));
     451    EXPECT_TRUE(hashSet.remove({ ExampleFlags::A }));
     452    EXPECT_TRUE(hashSet.remove({ ExampleFlags::A, ExampleFlags::B }));
     453    EXPECT_TRUE(hashSet.add(OptionSet<ExampleFlags>()).isNewEntry);
     454    EXPECT_TRUE(hashSet.add({ ExampleFlags::A }).isNewEntry);
     455    EXPECT_TRUE(hashSet.add({ ExampleFlags::A, ExampleFlags::B }).isNewEntry);
     456}
     457
    439458} // namespace TestWebKitAPI
Note: See TracChangeset for help on using the changeset viewer.