Changeset 196802 in webkit


Ignore:
Timestamp:
Feb 18, 2016 11:22:36 PM (8 years ago)
Author:
Brent Fulgham
Message:

Extend HashCountedSet with a method to efficiently set the count of an entry
https://bugs.webkit.org/show_bug.cgi?id=154352

Reviewed by Geoffrey Garen.

Source/WebCore:

Tested by new TestWebKitAPI tests.

  • loader/ResourceLoadStatistics.cpp:

(WebCore::decodeHashCountedSet): Update to use new HashCountedSet::add method.

Source/WTF:

Tested by new TestWebKitAPI tests.

Update the HashCountedSet class with a new 'add' method to support efficient initialization of
the count of a given key. Also provide move and pointer template specializations to expand the
types of data that can be used as 'keys' in the HashCountedSet to match the underlying HashMap
implementation.

  • wtf/HashCountedSet.h:

(WTF::Traits>::add): Added new overload supporting a supplied count.

Tools:

  • TestWebKitAPI/CMakeLists.txt: Add new HashCountedSet test files.
  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Ditto.
  • TestWebKitAPI/Tests/WTF/HashCountedSet.cpp: Added.
Location:
trunk
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r196800 r196802  
     12016-02-18  Brent Fulgham  <bfulgham@apple.com>
     2
     3        Extend HashCountedSet with a method to efficiently set the count of an entry
     4        https://bugs.webkit.org/show_bug.cgi?id=154352
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Tested by new TestWebKitAPI tests.
     9
     10        Update the HashCountedSet class with a new 'add' method to support efficient initialization of
     11        the count of a given key. Also provide move and pointer template specializations to expand the
     12        types of data that can be used as 'keys' in the HashCountedSet to match the underlying HashMap
     13        implementation.
     14
     15        * wtf/HashCountedSet.h:
     16        (WTF::Traits>::add): Added new overload supporting a supplied count.
     17
    1182016-02-18  Commit Queue  <commit-queue@webkit.org>
    219
  • trunk/Source/WTF/wtf/HashCountedSet.h

    r196800 r196802  
    11/*
    2  * Copyright (C) 2005, 2006, 2008, 2013 Apple Inc. All rights reserved.
     2 * Copyright (C) 2005, 2006, 2008, 2013, 2016 Apple Inc. All rights reserved.
    33 *
    44 * This library is free software; you can redistribute it and/or
     
    2222#define WTF_HashCountedSet_h
    2323
     24#include <initializer_list>
    2425#include <wtf/Assertions.h>
    2526#include <wtf/HashMap.h>
     
    3839        typedef typename ImplType::const_iterator const_iterator;
    3940        typedef typename ImplType::AddResult AddResult;
     41
     42        HashCountedSet()
     43        {
     44        }
     45
     46        HashCountedSet(std::initializer_list<typename ImplType::KeyValuePairType> initializerList)
     47        {
     48            for (const auto& keyValuePair : initializerList)
     49                add(keyValuePair.key, keyValuePair.value);
     50        }
     51
     52        HashCountedSet(std::initializer_list<typename ImplType::KeyType> initializerList)
     53        {
     54            for (const auto& value : initializerList)
     55                add(value);
     56        }
    4057       
    4158        void swap(HashCountedSet&);
     
    6077        // and an isNewEntry bool that indicates whether it is a new or existing entry.
    6178        AddResult add(const ValueType&);
    62        
     79        AddResult add(ValueType&&);
     80
     81        // Increments the count of a value by the passed amount.
     82        AddResult add(const ValueType&, unsigned);
     83        AddResult add(ValueType&&, unsigned);
     84
    6385        // Decrements the count of the value, and removes it if count goes down to zero.
    6486        // Returns true if the value is removed.
     
    7496        void clear();
    7597
     98        // Overloads for smart pointer keys that take the raw pointer type as the parameter.
     99        template<typename V = ValueType> typename std::enable_if<IsSmartPtr<V>::value, iterator>::type find(typename GetPtrHelper<V>::PtrType);
     100        template<typename V = ValueType> typename std::enable_if<IsSmartPtr<V>::value, const_iterator>::type find(typename GetPtrHelper<V>::PtrType) const;
     101        template<typename V = ValueType> typename std::enable_if<IsSmartPtr<V>::value, bool>::type contains(typename GetPtrHelper<V>::PtrType) const;
     102        template<typename V = ValueType> typename std::enable_if<IsSmartPtr<V>::value, unsigned>::type count(typename GetPtrHelper<V>::PtrType) const;
     103        template<typename V = ValueType> typename std::enable_if<IsSmartPtr<V>::value, bool>::type remove(typename GetPtrHelper<V>::PtrType);
     104
    76105    private:
    77106        ImplType m_impl;
    78107    };
    79108
     109
    80110    template<typename Value, typename HashFunctions, typename Traits>
    81111    inline void HashCountedSet<Value, HashFunctions, Traits>::swap(HashCountedSet& other)
     
    155185        AddResult result = m_impl.add(value, 0);
    156186        ++result.iterator->value;
     187        return result;
     188    }
     189
     190    template<typename Value, typename HashFunctions, typename Traits>
     191    inline typename HashCountedSet<Value, HashFunctions, Traits>::AddResult HashCountedSet<Value, HashFunctions, Traits>::add(ValueType&& value)
     192    {
     193        AddResult result = m_impl.add(std::forward<Value>(value), 0);
     194        ++result.iterator->value;
     195        return result;
     196    }
     197
     198    template<typename Value, typename HashFunctions, typename Traits>
     199    inline typename HashCountedSet<Value, HashFunctions, Traits>::AddResult HashCountedSet<Value, HashFunctions, Traits>::add(const ValueType& value, unsigned count)
     200    {
     201        AddResult result = m_impl.add(value, 0);
     202        result.iterator->value += count;
     203        return result;
     204    }
     205   
     206    template<typename Value, typename HashFunctions, typename Traits>
     207    inline typename HashCountedSet<Value, HashFunctions, Traits>::AddResult HashCountedSet<Value, HashFunctions, Traits>::add(ValueType&& value, unsigned count)
     208    {
     209        AddResult result = m_impl.add(std::forward<Value>(value), 0);
     210        result.iterator->value += count;
    157211        return result;
    158212    }
     
    230284    }
    231285
    232 
    233 } // namespace khtml
     286    template<typename Value, typename HashFunctions, typename Traits>
     287    template<typename V>
     288    inline auto HashCountedSet<Value, HashFunctions, Traits>::find(typename GetPtrHelper<V>::PtrType value) -> typename std::enable_if<IsSmartPtr<V>::value, iterator>::type
     289    {
     290        return m_impl.find(value);
     291    }
     292   
     293    template<typename Value, typename HashFunctions, typename Traits>
     294    template<typename V>
     295    inline auto HashCountedSet<Value, HashFunctions, Traits>::find(typename GetPtrHelper<V>::PtrType value) const -> typename std::enable_if<IsSmartPtr<V>::value, const_iterator>::type
     296    {
     297        return m_impl.find(value);
     298    }
     299   
     300    template<typename Value, typename HashFunctions, typename Traits>
     301    template<typename V>
     302    inline auto HashCountedSet<Value, HashFunctions, Traits>::contains(typename GetPtrHelper<V>::PtrType value) const -> typename std::enable_if<IsSmartPtr<V>::value, bool>::type
     303    {
     304        return m_impl.contains(value);
     305    }
     306   
     307    template<typename Value, typename HashFunctions, typename Traits>
     308    template<typename V>
     309    inline auto HashCountedSet<Value, HashFunctions, Traits>::count(typename GetPtrHelper<V>::PtrType value) const -> typename std::enable_if<IsSmartPtr<V>::value, unsigned>::type
     310    {
     311        return m_impl.get(value);
     312    }
     313   
     314    template<typename Value, typename HashFunctions, typename Traits>
     315    template<typename V>
     316    inline auto HashCountedSet<Value, HashFunctions, Traits>::remove(typename GetPtrHelper<V>::PtrType value) -> typename std::enable_if<IsSmartPtr<V>::value, bool>::type
     317    {
     318        return remove(find(value));
     319    }
     320
     321} // namespace WTF
    234322
    235323using WTF::HashCountedSet;
  • trunk/Source/WebCore/ChangeLog

    r196801 r196802  
     12016-02-18  Brent Fulgham  <bfulgham@apple.com>
     2
     3        Extend HashCountedSet with a method to efficiently set the count of an entry
     4        https://bugs.webkit.org/show_bug.cgi?id=154352
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Tested by new TestWebKitAPI tests.
     9
     10        * loader/ResourceLoadStatistics.cpp:
     11        (WebCore::decodeHashCountedSet): Update to use new HashCountedSet::add method.
     12
    1132016-02-18  Commit Queue  <commit-queue@webkit.org>
    214
  • trunk/Source/WebCore/loader/ResourceLoadStatistics.cpp

    r196800 r196802  
    125125        if (!decoderInner.decodeUInt32("count", count))
    126126            return false;
    127        
    128         // FIXME: Create a HashCountedSet method to do this efficiently
    129         for (unsigned i = 0; i < count; ++i)
    130             hashCountedSet.add(origin);
     127
     128        hashCountedSet.add(origin, count);
    131129        return true;
    132130    });
  • trunk/Tools/ChangeLog

    r196800 r196802  
     12016-02-18  Brent Fulgham  <bfulgham@apple.com>
     2
     3        Extend HashCountedSet with a method to efficiently set the count of an entry
     4        https://bugs.webkit.org/show_bug.cgi?id=154352
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        * TestWebKitAPI/CMakeLists.txt: Add new HashCountedSet test files.
     9        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Ditto.
     10        * TestWebKitAPI/Tests/WTF/HashCountedSet.cpp: Added.
     11
    1122016-02-18  Commit Queue  <commit-queue@webkit.org>
    213
  • trunk/Tools/TestWebKitAPI/CMakeLists.txt

    r196800 r196802  
    4848    ${TESTWEBKITAPI_DIR}/Tests/WTF/Deque.cpp
    4949    ${TESTWEBKITAPI_DIR}/Tests/WTF/Functional.cpp
     50    ${TESTWEBKITAPI_DIR}/Tests/WTF/HashCountedSet.cpp
    5051    ${TESTWEBKITAPI_DIR}/Tests/WTF/HashMap.cpp
    5152    ${TESTWEBKITAPI_DIR}/Tests/WTF/HashSet.cpp
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r196800 r196802  
    8080                76E182DF154767E600F1FADD /* auto-submitting-form.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 76E182DE15475A8300F1FADD /* auto-submitting-form.html */; };
    8181                7A1458FC1AD5C07000E06772 /* mouse-button-listener.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 7A1458FB1AD5C03500E06772 /* mouse-button-listener.html */; };
     82                7A38D7E61C752D5F004F157D /* HashCountedSet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A38D7E51C752D5F004F157D /* HashCountedSet.cpp */; };
    8283                7A5623111AD5AF3E0096B920 /* MenuTypesForMouseEvents.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A5623101AD5AF3E0096B920 /* MenuTypesForMouseEvents.cpp */; };
    8384                7A99D9941AD4A29D00373141 /* MenuTypesForMouseEvents.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7A99D9931AD4A29D00373141 /* MenuTypesForMouseEvents.mm */; };
     
    611612                76E182DE15475A8300F1FADD /* auto-submitting-form.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "auto-submitting-form.html"; sourceTree = "<group>"; };
    612613                7A1458FB1AD5C03500E06772 /* mouse-button-listener.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "mouse-button-listener.html"; sourceTree = "<group>"; };
     614                7A38D7E51C752D5F004F157D /* HashCountedSet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HashCountedSet.cpp; sourceTree = "<group>"; };
    613615                7A5623101AD5AF3E0096B920 /* MenuTypesForMouseEvents.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MenuTypesForMouseEvents.cpp; sourceTree = "<group>"; };
    614616                7A99D9931AD4A29D00373141 /* MenuTypesForMouseEvents.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MenuTypesForMouseEvents.mm; sourceTree = "<group>"; };
     
    12291231                                E4A757D3178AEA5B00B5D7A4 /* Deque.cpp */,
    12301232                                1AA9E55714980A9900001A8A /* Functional.cpp */,
     1233                                7A38D7E51C752D5F004F157D /* HashCountedSet.cpp */,
    12311234                                0BCD833414857CE400EA2003 /* HashMap.cpp */,
    12321235                                26B2DFF815BDE599004F691D /* HashSet.cpp */,
     
    18641867                                1A4F81CC1BDFFD37004E672E /* RemoteObjectRegistry.mm in Sources */,
    18651868                                51CB4AD81B3A079C00C1B1C6 /* ModalAlertsSPI.cpp in Sources */,
     1869                                7A38D7E61C752D5F004F157D /* HashCountedSet.cpp in Sources */,
    18661870                                9B7916501BD89D0D00D50B8F /* FirstResponderScrollingPosition.mm in Sources */,
    18671871                                1CF0D3791BBF2F3D00B4EF54 /* WKRetainPtr.cpp in Sources */,
Note: See TracChangeset for help on using the changeset viewer.