RESOLVED FIXED 228630
Add a HashTraits implementation for LayoutUnit
https://bugs.webkit.org/show_bug.cgi?id=228630
Summary Add a HashTraits implementation for LayoutUnit
Martin Robinson
Reported 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.
Attachments
Patch (4.23 KB, patch)
2021-08-02 04:45 PDT, Martin Robinson
no flags
Patch (4.11 KB, patch)
2021-08-03 02:50 PDT, Martin Robinson
no flags
Patch (4.31 KB, patch)
2021-08-04 01:42 PDT, Martin Robinson
no flags
Martin Robinson
Comment 1 2021-08-02 04:45:50 PDT
Fujii Hironori
Comment 2 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>.
Martin Robinson
Comment 3 2021-08-03 02:50:57 PDT
Martin Robinson
Comment 4 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.
Fujii Hironori
Comment 5 2021-08-03 12:57:13 PDT
Comment on attachment 434823 [details] Patch Nice. LGTM.
Darin Adler
Comment 6 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?
Martin Robinson
Comment 7 2021-08-04 01:42:59 PDT
Martin Robinson
Comment 8 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.
EWS
Comment 9 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].
Radar WebKit Bug Importer
Comment 10 2021-08-04 05:58:17 PDT
Note You need to log in before you can comment on or make changes to this bug.