Bug 178169 - It should be possible to iterate just the values (and not the counts) of a HashCountedSet
Summary: It should be possible to iterate just the values (and not the counts) of a Ha...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Template Framework (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Sam Weinig
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2017-10-11 07:38 PDT by Sam Weinig
Modified: 2017-10-12 05:47 PDT (History)
9 users (show)

See Also:


Attachments
Patch (25.05 KB, patch)
2017-10-11 07:49 PDT, Sam Weinig
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sam Weinig 2017-10-11 07:38:37 PDT
It should be possible to iterate just the values (and not the counts) of a HashCountedSet
Comment 1 Sam Weinig 2017-10-11 07:49:24 PDT
Created attachment 323415 [details]
Patch
Comment 2 Build Bot 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.
Comment 3 Daniel Bates 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.
Comment 4 Daniel Bates 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.
Comment 5 Sam Weinig 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.
Comment 6 WebKit Commit Bot 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>
Comment 7 WebKit Commit Bot 2017-10-12 05:46:02 PDT
All reviewed patches have been landed.  Closing bug.
Comment 8 Radar WebKit Bug Importer 2017-10-12 05:47:07 PDT
<rdar://problem/34954222>