Bug 228630 - Add a HashTraits implementation for LayoutUnit
Summary: Add a HashTraits implementation for LayoutUnit
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Martin Robinson
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-07-29 20:57 PDT by Martin Robinson
Modified: 2021-08-04 05:58 PDT (History)
13 users (show)

See Also:


Attachments
Patch (4.23 KB, patch)
2021-08-02 04:45 PDT, Martin Robinson
no flags Details | Formatted Diff | Diff
Patch (4.11 KB, patch)
2021-08-03 02:50 PDT, Martin Robinson
no flags Details | Formatted Diff | Diff
Patch (4.31 KB, patch)
2021-08-04 01:42 PDT, Martin Robinson
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Robinson 2021-07-29 20:57:21 PDT
In the scroll snapping code we are converting LayoutUnits to float in order to hash them. This runs the risk of introducing floating point errors.
Comment 1 Martin Robinson 2021-08-02 04:45:50 PDT
Created attachment 434746 [details]
Patch
Comment 2 Fujii Hironori 2021-08-02 22:12:06 PDT
Comment on attachment 434746 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=434746&action=review

> Source/WebCore/platform/LayoutUnit.h:847
> +    static unsigned hash(const WebCore::LayoutUnit& p) { return intHash(bitwise_cast<Bits>(p.rawValue())); }

I prefer DefaultHash<int>::hash(p.rawValue()) rather than bitwise_cast.

> Source/WebCore/platform/LayoutUnit.h:865
> +template<> struct DefaultHash<WebCore::LayoutUnit> : LayoutUnitHash { };

I prefer not having unnecessary LayoutUnitHash class. Simply merge the members to DefaultHash<WebCore::LayoutUnit>.
Comment 3 Martin Robinson 2021-08-03 02:50:57 PDT
Created attachment 434823 [details]
Patch
Comment 4 Martin Robinson 2021-08-03 02:51:35 PDT
(In reply to Fujii Hironori from comment #2)
> Comment on attachment 434746 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=434746&action=review
> 
> > Source/WebCore/platform/LayoutUnit.h:847
> > +    static unsigned hash(const WebCore::LayoutUnit& p) { return intHash(bitwise_cast<Bits>(p.rawValue())); }
> 
> I prefer DefaultHash<int>::hash(p.rawValue()) rather than bitwise_cast.
> 
> > Source/WebCore/platform/LayoutUnit.h:865
> > +template<> struct DefaultHash<WebCore::LayoutUnit> : LayoutUnitHash { };
> 
> I prefer not having unnecessary LayoutUnitHash class. Simply merge the
> members to DefaultHash<WebCore::LayoutUnit>.


Thanks for the review! I've uploaded a new version of the change addressing these concerns.
Comment 5 Fujii Hironori 2021-08-03 12:57:13 PDT
Comment on attachment 434823 [details]
Patch

Nice. LGTM.
Comment 6 Darin Adler 2021-08-03 13:17:36 PDT
Comment on attachment 434823 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=434823&action=review

This is great. Note that this could have been done entirely within ScrollSnapOffsetsInfo.cpp, but I think it’s OK as is.

> Source/WebCore/platform/LayoutUnit.h:851
> +// The empty value is INT_MIN, the deleted value is INT_MAX;

Comments should say *why* not just *what*. What guarantees these values aren’t needed in hash tables? Why are these good choices?
Comment 7 Martin Robinson 2021-08-04 01:42:59 PDT
Created attachment 434894 [details]
Patch
Comment 8 Martin Robinson 2021-08-04 05:30:17 PDT
(In reply to Darin Adler from comment #6)
> Comment on attachment 434823 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=434823&action=review
> 
> This is great. Note that this could have been done entirely within
> ScrollSnapOffsetsInfo.cpp, but I think it’s OK as is.
> 
> > Source/WebCore/platform/LayoutUnit.h:851
> > +// The empty value is INT_MIN, the deleted value is INT_MAX;
> 
> Comments should say *why* not just *what*. What guarantees these values
> aren’t needed in hash tables? Why are these good choices?

I've done my best to explain the reasoning for these choices.
Comment 9 EWS 2021-08-04 05:57:10 PDT
Committed r280632 (240245@main): <https://commits.webkit.org/240245@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 434894 [details].
Comment 10 Radar WebKit Bug Importer 2021-08-04 05:58:17 PDT
<rdar://problem/81511360>