⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 280632 in webkit


Ignore:
Timestamp:
Aug 4, 2021, 5:57:03 AM (5 years ago)
Author:
Martin Robinson
Message:

Add a HashTraits implementation for LayoutUnit
https://bugs.webkit.org/show_bug.cgi?id=228630

Reviewed by Fujii Hironori.

No new tests. This should not change behavior in an easily-observable way, but
could prevent rare hashing problems in the future.

  • page/scrolling/ScrollSnapOffsetsInfo.cpp:

(WebCore::updateSnapOffsetsForScrollableArea): Use LayoutUnit as the hash, which avoids
and extra conversion to float.

  • platform/LayoutUnit.h: Add a HashTraits implementation for LayoutUnit.
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r280631 r280632  
     12021-08-04  Martin Robinson  <mrobinson@webkit.org>
     2
     3        Add a HashTraits implementation for LayoutUnit
     4        https://bugs.webkit.org/show_bug.cgi?id=228630
     5
     6        Reviewed by Fujii Hironori.
     7
     8        No new tests. This should not change behavior in an easily-observable way, but
     9        could prevent rare hashing problems in the future.
     10
     11        * page/scrolling/ScrollSnapOffsetsInfo.cpp:
     12        (WebCore::updateSnapOffsetsForScrollableArea): Use LayoutUnit as the hash, which avoids
     13        and extra conversion to float.
     14        * platform/LayoutUnit.h: Add a HashTraits implementation for LayoutUnit.
     15
    1162021-08-04  Cathie Chen  <cathiechen@igalia.com>
    217
  • trunk/Source/WebCore/page/scrolling/ScrollSnapOffsetsInfo.cpp

    r280527 r280632  
    230230    }
    231231
    232     auto addOrUpdateStopForSnapOffset = [](HashMap<float, SnapOffset<LayoutUnit>>& offsets, LayoutUnit newOffset, ScrollSnapStop stop, bool hasSnapAreaLargerThanViewport, size_t snapAreaIndices)
     232    auto addOrUpdateStopForSnapOffset = [](HashMap<LayoutUnit, SnapOffset<LayoutUnit>>& offsets, LayoutUnit newOffset, ScrollSnapStop stop, bool hasSnapAreaLargerThanViewport, size_t snapAreaIndices)
    233233    {
    234234        auto offset = offsets.ensure(newOffset, [&] {
     
    244244    };
    245245
    246     HashMap<float, SnapOffset<LayoutUnit>> verticalSnapOffsetsMap;
    247     HashMap<float, SnapOffset<LayoutUnit>> horizontalSnapOffsetsMap;
     246    HashMap<LayoutUnit, SnapOffset<LayoutUnit>> verticalSnapOffsetsMap;
     247    HashMap<LayoutUnit, SnapOffset<LayoutUnit>> horizontalSnapOffsetsMap;
    248248    Vector<LayoutRect> snapAreas;
    249249
  • trunk/Source/WebCore/platform/LayoutUnit.h

    r277744 r280632  
    3535#include <math.h>
    3636#include <stdlib.h>
     37#include <wtf/HashTraits.h>
    3738#include <wtf/MathExtras.h>
    3839#include <wtf/SaturatedArithmetic.h>
     
    839840
    840841} // namespace WebCore
     842
     843namespace WTF {
     844
     845template<> struct DefaultHash<WebCore::LayoutUnit> {
     846    static unsigned hash(const WebCore::LayoutUnit& p) { return DefaultHash<int>::hash(p.rawValue()); }
     847    static bool equal(const WebCore::LayoutUnit& a, const WebCore::LayoutUnit& b) { return a == b; }
     848    static const bool safeToCompareToEmptyOrDeleted = true;
     849};
     850
     851// The empty value is INT_MIN, the deleted value is INT_MAX. During the course of layout
     852// these values are typically only used to represent uninitialized values, so they are
     853// good candidates to represent the deleted and empty values in HashMaps as well.
     854template<> struct HashTraits<WebCore::LayoutUnit> : GenericHashTraits<WebCore::LayoutUnit> {
     855    static constexpr bool emptyValueIsZero = false;
     856    static WebCore::LayoutUnit emptyValue()
     857    {
     858        WebCore::LayoutUnit value;
     859        value.setRawValue(std::numeric_limits<int>::min());
     860        return value;
     861    }
     862    static void constructDeletedValue(WebCore::LayoutUnit& slot) { slot.setRawValue(std::numeric_limits<int>::max()); }
     863    static bool isDeletedValue(WebCore::LayoutUnit value) { return value.rawValue() == std::numeric_limits<int>::max(); }
     864};
     865
     866} // namespace WTF
Note: See TracChangeset for help on using the changeset viewer.