Changeset 238467 in webkit
- Timestamp:
- Nov 23, 2018, 10:08:31 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
-
Source/WTF/ChangeLog (modified) (1 diff)
-
Source/WTF/wtf/ListHashSet.h (modified) (2 diffs)
-
Tools/ChangeLog (modified) (1 diff)
-
Tools/TestWebKitAPI/Tests/WTF/HashSet.cpp (modified) (1 diff)
-
Tools/TestWebKitAPI/Tests/WTF/ListHashSet.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r238439 r238467 1 2018-11-23 Sam Weinig <sam@webkit.org> 2 3 Add raw pointer overloads to ListHashSet via SmartPtr specialized functions 4 https://bugs.webkit.org/show_bug.cgi?id=191936 5 6 Reviewed by Zalan Bujtas. 7 8 Adds overloads for find, contains, insertBefore and remove that take raw pointers 9 when the value type V of a ListHashSet is true for the predicate IsSmartPtr<V>::value. 10 This brings the interface to ListHashSet closer inline with HashSet, HashMap and HashCountedSet 11 which already have this functionality. Like in the other collections, this is especially 12 useful when using std::unique_ptr<> as the value, since there would be no way to pass it 13 to these functions. One difference between this set of overloads is the inclusion of insertBefore, 14 which is unique to ListHashSet. As would be expected, this specialization only changes the first 15 parameter, the one that needs to be found, to support a raw pointer. 16 17 * wtf/ListHashSet.h: 18 (WTF::U>::find): 19 (WTF::U>::find const): 20 (WTF::U>::contains const): 21 (WTF::U>::insertBefore): 22 (WTF::U>::remove): 23 1 24 2018-11-21 Yusuke Suzuki <yusukesuzuki@slowstart.org> 2 25 -
trunk/Source/WTF/wtf/ListHashSet.h
r237419 r238467 143 143 void clear(); 144 144 145 // Overloads for smart pointer values that take the raw pointer type as the parameter. 146 template<typename V = ValueType> typename std::enable_if<IsSmartPtr<V>::value, iterator>::type find(typename GetPtrHelper<V>::PtrType); 147 template<typename V = ValueType> typename std::enable_if<IsSmartPtr<V>::value, const_iterator>::type find(typename GetPtrHelper<V>::PtrType) const; 148 template<typename V = ValueType> typename std::enable_if<IsSmartPtr<V>::value, bool>::type contains(typename GetPtrHelper<V>::PtrType) const; 149 template<typename V = ValueType> typename std::enable_if<IsSmartPtr<V>::value, AddResult>::type insertBefore(typename GetPtrHelper<V>::PtrType, const ValueType&); 150 template<typename V = ValueType> typename std::enable_if<IsSmartPtr<V>::value, AddResult>::type insertBefore(typename GetPtrHelper<V>::PtrType, ValueType&&); 151 template<typename V = ValueType> typename std::enable_if<IsSmartPtr<V>::value, bool>::type remove(typename GetPtrHelper<V>::PtrType); 152 145 153 private: 146 154 void unlink(Node*); … … 627 635 628 636 template<typename T, typename U> 637 template<typename V> 638 inline auto ListHashSet<T, U>::find(typename GetPtrHelper<V>::PtrType value) -> typename std::enable_if<IsSmartPtr<V>::value, iterator>::type 639 { 640 auto it = m_impl.template find<BaseTranslator>(value); 641 if (it == m_impl.end()) 642 return end(); 643 return makeIterator(*it); 644 } 645 646 template<typename T, typename U> 647 template<typename V> 648 inline auto ListHashSet<T, U>::find(typename GetPtrHelper<V>::PtrType value) const -> typename std::enable_if<IsSmartPtr<V>::value, const_iterator>::type 649 { 650 auto it = m_impl.template find<BaseTranslator>(value); 651 if (it == m_impl.end()) 652 return end(); 653 return makeConstIterator(*it); 654 } 655 656 template<typename T, typename U> 657 template<typename V> 658 inline auto ListHashSet<T, U>::contains(typename GetPtrHelper<V>::PtrType value) const -> typename std::enable_if<IsSmartPtr<V>::value, bool>::type 659 { 660 return m_impl.template contains<BaseTranslator>(value); 661 } 662 663 template<typename T, typename U> 664 template<typename V> 665 inline auto ListHashSet<T, U>::insertBefore(typename GetPtrHelper<V>::PtrType beforeValue, const ValueType& newValue) -> typename std::enable_if<IsSmartPtr<V>::value, AddResult>::type 666 { 667 return insertBefore(find(beforeValue), newValue); 668 } 669 670 template<typename T, typename U> 671 template<typename V> 672 inline auto ListHashSet<T, U>::insertBefore(typename GetPtrHelper<V>::PtrType beforeValue, ValueType&& newValue) -> typename std::enable_if<IsSmartPtr<V>::value, AddResult>::type 673 { 674 return insertBefore(find(beforeValue), WTFMove(newValue)); 675 } 676 677 template<typename T, typename U> 678 template<typename V> 679 inline auto ListHashSet<T, U>::remove(typename GetPtrHelper<V>::PtrType value) -> typename std::enable_if<IsSmartPtr<V>::value, bool>::type 680 { 681 return remove(find(value)); 682 } 683 684 template<typename T, typename U> 629 685 void ListHashSet<T, U>::unlink(Node* node) 630 686 { -
trunk/Tools/ChangeLog
r238461 r238467 1 2018-11-23 Sam Weinig <sam@webkit.org> 2 3 Add raw pointer overloads to ListHashSet via SmartPtr specialized functions 4 https://bugs.webkit.org/show_bug.cgi?id=191936 5 6 Reviewed by Zalan Bujtas. 7 8 Adds tests for raw pointer overloads in ListHashSet. 9 10 * TestWebKitAPI/Tests/WTF/HashSet.cpp: 11 * TestWebKitAPI/Tests/WTF/ListHashSet.cpp: 12 1 13 2018-11-23 Wenson Hsieh <wenson_hsieh@apple.com> 2 14 -
trunk/Tools/TestWebKitAPI/Tests/WTF/HashSet.cpp
r237461 r238467 37 37 38 38 template<int initialCapacity> 39 struct InitialCapacityTestHashTraits : public WTF::UnsignedWithZeroKeyHashTraits<int> {39 struct InitialCapacityTestHashTraits : public WTF::UnsignedWithZeroKeyHashTraits<int> { 40 40 static const int minimumTableSize = initialCapacity; 41 41 }; -
trunk/Tools/TestWebKitAPI/Tests/WTF/ListHashSet.cpp
r223041 r238467 26 26 #include "config.h" 27 27 28 #include "Counters.h" 28 29 #include "MoveOnly.h" 29 30 #include <wtf/ListHashSet.h> … … 374 375 } 375 376 377 TEST(WTF_ListHashSet, UniquePtrKey) 378 { 379 ConstructorDestructorCounter::TestingScope scope; 380 381 ListHashSet<std::unique_ptr<ConstructorDestructorCounter>> list; 382 383 auto uniquePtr = std::make_unique<ConstructorDestructorCounter>(); 384 list.add(WTFMove(uniquePtr)); 385 386 EXPECT_EQ(1u, ConstructorDestructorCounter::constructionCount); 387 EXPECT_EQ(0u, ConstructorDestructorCounter::destructionCount); 388 389 list.clear(); 390 391 EXPECT_EQ(1u, ConstructorDestructorCounter::constructionCount); 392 EXPECT_EQ(1u, ConstructorDestructorCounter::destructionCount); 393 } 394 395 TEST(WTF_ListHashSet, UniquePtrKey_FindUsingRawPointer) 396 { 397 ListHashSet<std::unique_ptr<int>> list; 398 399 auto uniquePtr = std::make_unique<int>(5); 400 auto ptr = uniquePtr.get(); 401 list.add(WTFMove(uniquePtr)); 402 403 auto it = list.find(ptr); 404 ASSERT_TRUE(it != list.end()); 405 EXPECT_EQ(ptr, it->get()); 406 EXPECT_EQ(5, *it->get()); 407 } 408 409 TEST(WTF_ListHashSet, UniquePtrKey_ContainsUsingRawPointer) 410 { 411 ListHashSet<std::unique_ptr<int>> list; 412 413 auto uniquePtr = std::make_unique<int>(5); 414 auto ptr = uniquePtr.get(); 415 list.add(WTFMove(uniquePtr)); 416 417 EXPECT_EQ(true, list.contains(ptr)); 418 } 419 420 TEST(WTF_ListHashSet, UniquePtrKey_InsertBeforeUsingRawPointer) 421 { 422 ListHashSet<std::unique_ptr<int>> list; 423 424 auto uniquePtrWith2 = std::make_unique<int>(2); 425 auto ptrWith2 = uniquePtrWith2.get(); 426 auto uniquePtrWith4 = std::make_unique<int>(4); 427 auto ptrWith4 = uniquePtrWith4.get(); 428 429 list.add(WTFMove(uniquePtrWith2)); 430 list.add(WTFMove(uniquePtrWith4)); 431 432 // { 2, 4 } 433 ASSERT_EQ(ptrWith2, list.first().get()); 434 ASSERT_EQ(2, *list.first().get()); 435 ASSERT_EQ(ptrWith4, list.last().get()); 436 ASSERT_EQ(4, *list.last().get()); 437 438 auto uniquePtrWith3 = std::make_unique<int>(3); 439 auto ptrWith3 = uniquePtrWith3.get(); 440 441 list.insertBefore(ptrWith4, WTFMove(uniquePtrWith3)); 442 443 // { 2, 3, 4 } 444 auto firstWith2 = list.takeFirst(); 445 ASSERT_EQ(ptrWith2, firstWith2.get()); 446 ASSERT_EQ(2, *firstWith2); 447 448 auto firstWith3 = list.takeFirst(); 449 ASSERT_EQ(ptrWith3, firstWith3.get()); 450 ASSERT_EQ(3, *firstWith3); 451 452 auto firstWith4 = list.takeFirst(); 453 ASSERT_EQ(ptrWith2, firstWith4.get()); 454 ASSERT_EQ(4, *firstWith4); 455 456 ASSERT_TRUE(list.isEmpty()); 457 } 458 459 TEST(WTF_ListHashSet, UniquePtrKey_RemoveUsingRawPointer) 460 { 461 ConstructorDestructorCounter::TestingScope scope; 462 463 ListHashSet<std::unique_ptr<ConstructorDestructorCounter>> list; 464 465 auto uniquePtr = std::make_unique<ConstructorDestructorCounter>(); 466 auto* ptr = uniquePtr.get(); 467 list.add(WTFMove(uniquePtr)); 468 469 EXPECT_EQ(1u, ConstructorDestructorCounter::constructionCount); 470 EXPECT_EQ(0u, ConstructorDestructorCounter::destructionCount); 471 472 bool result = list.remove(ptr); 473 EXPECT_EQ(true, result); 474 475 EXPECT_EQ(1u, ConstructorDestructorCounter::constructionCount); 476 EXPECT_EQ(1u, ConstructorDestructorCounter::destructionCount); 477 } 478 376 479 } // namespace TestWebKitAPI
Note:
See TracChangeset
for help on using the changeset viewer.