Bug 178169

Summary: It should be possible to iterate just the values (and not the counts) of a HashCountedSet
Product: WebKit Reporter: Sam Weinig <sam>
Component: Web Template FrameworkAssignee: Sam Weinig <sam>
Status: RESOLVED FIXED    
Severity: Normal CC: benjamin, buildbot, cdumez, cmarcelo, commit-queue, darin, dbates, thorton, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: All   
OS: All   
Attachments:
Description Flags
Patch none

Sam Weinig
Reported 2017-10-11 07:38:37 PDT
It should be possible to iterate just the values (and not the counts) of a HashCountedSet
Attachments
Patch (25.05 KB, patch)
2017-10-11 07:49 PDT, Sam Weinig
no flags
Sam Weinig
Comment 1 2017-10-11 07:49:24 PDT
Build Bot
Comment 2 2017-10-11 07:50:47 PDT
Attachment 323415 [details] did not pass style-queue: ERROR: Source/WTF/wtf/HashCountedSet.h:135: Tests for true/false, null/non-null, and zero/non-zero should all be done without equality comparisons. [readability/comparison_to_zero] [5] ERROR: Source/WTF/wtf/HashCountedSet.h:170: This { should be at the end of the previous line [whitespace/braces] [4] ERROR: Source/WTF/wtf/HashCountedSet.h:279: This { should be at the end of the previous line [whitespace/braces] [4] ERROR: Source/WTF/wtf/HashCountedSet.h:286: This { should be at the end of the previous line [whitespace/braces] [4] ERROR: Source/WTF/wtf/HashCountedSet.h:293: This { should be at the end of the previous line [whitespace/braces] [4] ERROR: Source/WTF/wtf/HashCountedSet.h:300: This { should be at the end of the previous line [whitespace/braces] [4] ERROR: Source/WTF/wtf/HashCountedSet.h:307: This { should be at the end of the previous line [whitespace/braces] [4] Total errors found: 7 in 4 files If any of these errors are false positives, please file a bug against check-webkit-style.
Daniel Bates
Comment 3 2017-10-11 23:32:30 PDT
Comment on attachment 323415 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=323415&action=review > Source/WTF/wtf/HashCountedSet.h:43 > + HashCountedSet() HashCountedSet() = default; > Source/WTF/wtf/HashCountedSet.h:103 > + template<typename V = ValueType> typename std::enable_if<IsSmartPtr<V>::value, iterator>::type find(typename GetPtrHelper<V>::PtrType); We should use enable_if_t<> to simplify this. > Source/WTF/wtf/HashCountedSet.h:104 > + template<typename V = ValueType> typename std::enable_if<IsSmartPtr<V>::value, const_iterator>::type find(typename GetPtrHelper<V>::PtrType) const; Ditto. > Source/WTF/wtf/HashCountedSet.h:105 > + template<typename V = ValueType> typename std::enable_if<IsSmartPtr<V>::value, bool>::type contains(typename GetPtrHelper<V>::PtrType) const; Ditto. > Source/WTF/wtf/HashCountedSet.h:106 > + template<typename V = ValueType> typename std::enable_if<IsSmartPtr<V>::value, unsigned>::type count(typename GetPtrHelper<V>::PtrType) const; Ditto. > Source/WTF/wtf/HashCountedSet.h:107 > + template<typename V = ValueType> typename std::enable_if<IsSmartPtr<V>::value, bool>::type remove(typename GetPtrHelper<V>::PtrType); Ditto. > Source/WTF/wtf/HashCountedSet.h:242 > + unsigned oldVal = it->value; oldVal => oldValue > Source/WTF/wtf/HashCountedSet.h:244 > + unsigned newVal = oldVal - 1; newVal => newValue > Source/WTF/wtf/HashCountedSet.h:278 > +inline auto HashCountedSet<Value, HashFunctions, Traits>::find(typename GetPtrHelper<V>::PtrType value) -> typename std::enable_if<IsSmartPtr<V>::value, iterator>::type We should use enable_if_t<> to simply this. > Source/WTF/wtf/HashCountedSet.h:285 > +inline auto HashCountedSet<Value, HashFunctions, Traits>::find(typename GetPtrHelper<V>::PtrType value) const -> typename std::enable_if<IsSmartPtr<V>::value, const_iterator>::type Ditto. > Source/WTF/wtf/HashCountedSet.h:292 > +inline auto HashCountedSet<Value, HashFunctions, Traits>::contains(typename GetPtrHelper<V>::PtrType value) const -> typename std::enable_if<IsSmartPtr<V>::value, bool>::type Ditto. > Source/WTF/wtf/HashCountedSet.h:299 > +inline auto HashCountedSet<Value, HashFunctions, Traits>::count(typename GetPtrHelper<V>::PtrType value) const -> typename std::enable_if<IsSmartPtr<V>::value, unsigned>::type Ditto. > Source/WTF/wtf/HashCountedSet.h:306 > +inline auto HashCountedSet<Value, HashFunctions, Traits>::remove(typename GetPtrHelper<V>::PtrType value) -> typename std::enable_if<IsSmartPtr<V>::value, bool>::type Ditto. > Source/WTF/wtf/HashCountedSet.h:314 > + typedef typename HashCountedSet<Value, HashFunctions, Traits>::const_iterator iterator; using ... = ...; > Source/WTF/wtf/HashCountedSet.h:327 > + typedef typename HashCountedSet<Value, HashFunctions, Traits>::const_iterator iterator; Ditto. > Source/WTF/wtf/HashCountedSet.h:333 > + for (unsigned i = 0; it != end; ++it, ++i) size_t > Tools/TestWebKitAPI/Tests/WTF/HashCountedSet.cpp:474 > + HashCountedSet<int> set { 1, 1, 2, 3, 3 }; You might want to consider adding more test coverage. Say, test the empty set, a set with exactly one value, a set with exactly two repeated values. Having said that the implementation of values() is just to turn around and call keys() and I would hope we have existing test coverage for this.
Daniel Bates
Comment 4 2017-10-11 23:36:21 PDT
(In reply to Daniel Bates from comment #3) > > Source/WTF/wtf/HashCountedSet.h:333 > > + for (unsigned i = 0; it != end; ++it, ++i) > > size_t > I know unsigned is good enough for all practical purposes. I still prefer size_t because it avoids an implicit conversion when calling operator[] and that makes me feel warm and fuzzy.
Sam Weinig
Comment 5 2017-10-12 05:18:12 PDT
Comment on attachment 323415 [details] Patch Thanks for the review Dan! I'll address the comments in a follow up that cleans up additional Hash related files.
WebKit Commit Bot
Comment 6 2017-10-12 05:46:00 PDT
Comment on attachment 323415 [details] Patch Clearing flags on attachment: 323415 Committed r223236: <https://trac.webkit.org/changeset/223236>
WebKit Commit Bot
Comment 7 2017-10-12 05:46:02 PDT
All reviewed patches have been landed. Closing bug.
Radar WebKit Bug Importer
Comment 8 2017-10-12 05:47:07 PDT
Note You need to log in before you can comment on or make changes to this bug.