Changeset 196802 in webkit
- Timestamp:
- Feb 18, 2016 11:22:36 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r196800 r196802 1 2016-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 1 18 2016-02-18 Commit Queue <commit-queue@webkit.org> 2 19 -
trunk/Source/WTF/wtf/HashCountedSet.h
r196800 r196802 1 1 /* 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. 3 3 * 4 4 * This library is free software; you can redistribute it and/or … … 22 22 #define WTF_HashCountedSet_h 23 23 24 #include <initializer_list> 24 25 #include <wtf/Assertions.h> 25 26 #include <wtf/HashMap.h> … … 38 39 typedef typename ImplType::const_iterator const_iterator; 39 40 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 } 40 57 41 58 void swap(HashCountedSet&); … … 60 77 // and an isNewEntry bool that indicates whether it is a new or existing entry. 61 78 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 63 85 // Decrements the count of the value, and removes it if count goes down to zero. 64 86 // Returns true if the value is removed. … … 74 96 void clear(); 75 97 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 76 105 private: 77 106 ImplType m_impl; 78 107 }; 79 108 109 80 110 template<typename Value, typename HashFunctions, typename Traits> 81 111 inline void HashCountedSet<Value, HashFunctions, Traits>::swap(HashCountedSet& other) … … 155 185 AddResult result = m_impl.add(value, 0); 156 186 ++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; 157 211 return result; 158 212 } … … 230 284 } 231 285 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 234 322 235 323 using WTF::HashCountedSet; -
trunk/Source/WebCore/ChangeLog
r196801 r196802 1 2016-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 1 13 2016-02-18 Commit Queue <commit-queue@webkit.org> 2 14 -
trunk/Source/WebCore/loader/ResourceLoadStatistics.cpp
r196800 r196802 125 125 if (!decoderInner.decodeUInt32("count", count)) 126 126 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); 131 129 return true; 132 130 }); -
trunk/Tools/ChangeLog
r196800 r196802 1 2016-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 1 12 2016-02-18 Commit Queue <commit-queue@webkit.org> 2 13 -
trunk/Tools/TestWebKitAPI/CMakeLists.txt
r196800 r196802 48 48 ${TESTWEBKITAPI_DIR}/Tests/WTF/Deque.cpp 49 49 ${TESTWEBKITAPI_DIR}/Tests/WTF/Functional.cpp 50 ${TESTWEBKITAPI_DIR}/Tests/WTF/HashCountedSet.cpp 50 51 ${TESTWEBKITAPI_DIR}/Tests/WTF/HashMap.cpp 51 52 ${TESTWEBKITAPI_DIR}/Tests/WTF/HashSet.cpp -
trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
r196800 r196802 80 80 76E182DF154767E600F1FADD /* auto-submitting-form.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 76E182DE15475A8300F1FADD /* auto-submitting-form.html */; }; 81 81 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 */; }; 82 83 7A5623111AD5AF3E0096B920 /* MenuTypesForMouseEvents.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A5623101AD5AF3E0096B920 /* MenuTypesForMouseEvents.cpp */; }; 83 84 7A99D9941AD4A29D00373141 /* MenuTypesForMouseEvents.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7A99D9931AD4A29D00373141 /* MenuTypesForMouseEvents.mm */; }; … … 611 612 76E182DE15475A8300F1FADD /* auto-submitting-form.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "auto-submitting-form.html"; sourceTree = "<group>"; }; 612 613 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>"; }; 613 615 7A5623101AD5AF3E0096B920 /* MenuTypesForMouseEvents.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MenuTypesForMouseEvents.cpp; sourceTree = "<group>"; }; 614 616 7A99D9931AD4A29D00373141 /* MenuTypesForMouseEvents.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MenuTypesForMouseEvents.mm; sourceTree = "<group>"; }; … … 1229 1231 E4A757D3178AEA5B00B5D7A4 /* Deque.cpp */, 1230 1232 1AA9E55714980A9900001A8A /* Functional.cpp */, 1233 7A38D7E51C752D5F004F157D /* HashCountedSet.cpp */, 1231 1234 0BCD833414857CE400EA2003 /* HashMap.cpp */, 1232 1235 26B2DFF815BDE599004F691D /* HashSet.cpp */, … … 1864 1867 1A4F81CC1BDFFD37004E672E /* RemoteObjectRegistry.mm in Sources */, 1865 1868 51CB4AD81B3A079C00C1B1C6 /* ModalAlertsSPI.cpp in Sources */, 1869 7A38D7E61C752D5F004F157D /* HashCountedSet.cpp in Sources */, 1866 1870 9B7916501BD89D0D00D50B8F /* FirstResponderScrollingPosition.mm in Sources */, 1867 1871 1CF0D3791BBF2F3D00B4EF54 /* WKRetainPtr.cpp in Sources */,
Note: See TracChangeset
for help on using the changeset viewer.