Title: [280632] trunk/Source/WebCore
- Revision
- 280632
- Author
- [email protected]
- Date
- 2021-08-04 05:57:03 -0700 (Wed, 04 Aug 2021)
Log 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.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (280631 => 280632)
--- trunk/Source/WebCore/ChangeLog 2021-08-04 10:57:08 UTC (rev 280631)
+++ trunk/Source/WebCore/ChangeLog 2021-08-04 12:57:03 UTC (rev 280632)
@@ -1,3 +1,18 @@
+2021-08-04 Martin Robinson <[email protected]>
+
+ 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.
+
2021-08-04 Cathie Chen <[email protected]>
REGRESSION (r277997) Images get stretched with aspect-ratio and max-width: x%
Modified: trunk/Source/WebCore/page/scrolling/ScrollSnapOffsetsInfo.cpp (280631 => 280632)
--- trunk/Source/WebCore/page/scrolling/ScrollSnapOffsetsInfo.cpp 2021-08-04 10:57:08 UTC (rev 280631)
+++ trunk/Source/WebCore/page/scrolling/ScrollSnapOffsetsInfo.cpp 2021-08-04 12:57:03 UTC (rev 280632)
@@ -229,7 +229,7 @@
return;
}
- auto addOrUpdateStopForSnapOffset = [](HashMap<float, SnapOffset<LayoutUnit>>& offsets, LayoutUnit newOffset, ScrollSnapStop stop, bool hasSnapAreaLargerThanViewport, size_t snapAreaIndices)
+ auto addOrUpdateStopForSnapOffset = [](HashMap<LayoutUnit, SnapOffset<LayoutUnit>>& offsets, LayoutUnit newOffset, ScrollSnapStop stop, bool hasSnapAreaLargerThanViewport, size_t snapAreaIndices)
{
auto offset = offsets.ensure(newOffset, [&] {
return SnapOffset<LayoutUnit> { newOffset, stop, hasSnapAreaLargerThanViewport, { } };
@@ -243,8 +243,8 @@
offset.iterator->value.snapAreaIndices.append(snapAreaIndices);
};
- HashMap<float, SnapOffset<LayoutUnit>> verticalSnapOffsetsMap;
- HashMap<float, SnapOffset<LayoutUnit>> horizontalSnapOffsetsMap;
+ HashMap<LayoutUnit, SnapOffset<LayoutUnit>> verticalSnapOffsetsMap;
+ HashMap<LayoutUnit, SnapOffset<LayoutUnit>> horizontalSnapOffsetsMap;
Vector<LayoutRect> snapAreas;
auto maxScrollOffset = scrollableArea.maximumScrollOffset();
Modified: trunk/Source/WebCore/platform/LayoutUnit.h (280631 => 280632)
--- trunk/Source/WebCore/platform/LayoutUnit.h 2021-08-04 10:57:08 UTC (rev 280631)
+++ trunk/Source/WebCore/platform/LayoutUnit.h 2021-08-04 12:57:03 UTC (rev 280632)
@@ -34,6 +34,7 @@
#include <limits>
#include <math.h>
#include <stdlib.h>
+#include <wtf/HashTraits.h>
#include <wtf/MathExtras.h>
#include <wtf/SaturatedArithmetic.h>
@@ -838,3 +839,28 @@
}
} // namespace WebCore
+
+namespace WTF {
+
+template<> struct DefaultHash<WebCore::LayoutUnit> {
+ static unsigned hash(const WebCore::LayoutUnit& p) { return DefaultHash<int>::hash(p.rawValue()); }
+ static bool equal(const WebCore::LayoutUnit& a, const WebCore::LayoutUnit& b) { return a == b; }
+ static const bool safeToCompareToEmptyOrDeleted = true;
+};
+
+// The empty value is INT_MIN, the deleted value is INT_MAX. During the course of layout
+// these values are typically only used to represent uninitialized values, so they are
+// good candidates to represent the deleted and empty values in HashMaps as well.
+template<> struct HashTraits<WebCore::LayoutUnit> : GenericHashTraits<WebCore::LayoutUnit> {
+ static constexpr bool emptyValueIsZero = false;
+ static WebCore::LayoutUnit emptyValue()
+ {
+ WebCore::LayoutUnit value;
+ value.setRawValue(std::numeric_limits<int>::min());
+ return value;
+ }
+ static void constructDeletedValue(WebCore::LayoutUnit& slot) { slot.setRawValue(std::numeric_limits<int>::max()); }
+ static bool isDeletedValue(WebCore::LayoutUnit value) { return value.rawValue() == std::numeric_limits<int>::max(); }
+};
+
+} // namespace WTF
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes