Changeset 280632 in webkit
- Timestamp:
- Aug 4, 2021, 5:57:03 AM (5 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
-
ChangeLog (modified) (1 diff)
-
page/scrolling/ScrollSnapOffsetsInfo.cpp (modified) (2 diffs)
-
platform/LayoutUnit.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r280631 r280632 1 2021-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 1 16 2021-08-04 Cathie Chen <cathiechen@igalia.com> 2 17 -
trunk/Source/WebCore/page/scrolling/ScrollSnapOffsetsInfo.cpp
r280527 r280632 230 230 } 231 231 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) 233 233 { 234 234 auto offset = offsets.ensure(newOffset, [&] { … … 244 244 }; 245 245 246 HashMap< float, SnapOffset<LayoutUnit>> verticalSnapOffsetsMap;247 HashMap< float, SnapOffset<LayoutUnit>> horizontalSnapOffsetsMap;246 HashMap<LayoutUnit, SnapOffset<LayoutUnit>> verticalSnapOffsetsMap; 247 HashMap<LayoutUnit, SnapOffset<LayoutUnit>> horizontalSnapOffsetsMap; 248 248 Vector<LayoutRect> snapAreas; 249 249 -
trunk/Source/WebCore/platform/LayoutUnit.h
r277744 r280632 35 35 #include <math.h> 36 36 #include <stdlib.h> 37 #include <wtf/HashTraits.h> 37 38 #include <wtf/MathExtras.h> 38 39 #include <wtf/SaturatedArithmetic.h> … … 839 840 840 841 } // namespace WebCore 842 843 namespace WTF { 844 845 template<> 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. 854 template<> 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.