Title: [283808] trunk
Revision
283808
Author
[email protected]
Date
2021-10-08 09:37:05 -0700 (Fri, 08 Oct 2021)

Log Message

Make WTF::IteratorRange reversible
https://bugs.webkit.org/show_bug.cgi?id=231415

Reviewed by Darin Adler.

Source/WebCore:

Replace a custom range type with the new reversible IteratorRange.

* layout/integration/LayoutIntegrationInlineContent.cpp:
(WebCore::LayoutIntegration:: const):
(WebCore::LayoutIntegration::InlineContent::boxesForRect const): Deleted.
* layout/integration/LayoutIntegrationInlineContent.h:
(WebCore::LayoutIntegration::InlineContent::BoxRange::begin const): Deleted.
(WebCore::LayoutIntegration::InlineContent::BoxRange::end const): Deleted.
(WebCore::LayoutIntegration::InlineContent::BoxRange::rbegin const): Deleted.
(WebCore::LayoutIntegration::InlineContent::BoxRange::rend const): Deleted.
* layout/integration/LayoutIntegrationLineLayout.cpp:
(WebCore::LayoutIntegration::LineLayout::hitTest):

Source/WTF:

Also export some names out of the WTF namespace.

* wtf/IteratorRange.h:
(WTF::IteratorRange::rbegin const):
(WTF::IteratorRange::rend const):

Tools:

* TestWebKitAPI/Tests/WTF/IteratorRange.cpp:
(TestWebKitAPI::TEST):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (283807 => 283808)


--- trunk/Source/WTF/ChangeLog	2021-10-08 16:32:02 UTC (rev 283807)
+++ trunk/Source/WTF/ChangeLog	2021-10-08 16:37:05 UTC (rev 283808)
@@ -1,3 +1,16 @@
+2021-10-08  Antti Koivisto  <[email protected]>
+
+        Make WTF::IteratorRange reversible
+        https://bugs.webkit.org/show_bug.cgi?id=231415
+
+        Reviewed by Darin Adler.
+
+        Also export some names out of the WTF namespace.
+
+        * wtf/IteratorRange.h:
+        (WTF::IteratorRange::rbegin const):
+        (WTF::IteratorRange::rend const):
+
 2021-10-07  Aditya Keerthi  <[email protected]>
 
         [css-ui] Parsing support for accent-color

Modified: trunk/Source/WTF/wtf/IteratorRange.h (283807 => 283808)


--- trunk/Source/WTF/wtf/IteratorRange.h	2021-10-08 16:32:02 UTC (rev 283807)
+++ trunk/Source/WTF/wtf/IteratorRange.h	2021-10-08 16:37:05 UTC (rev 283808)
@@ -33,6 +33,8 @@
 class IteratorRange {
     WTF_MAKE_FAST_ALLOCATED;
 public:
+    using reverse_iterator = std::reverse_iterator<Iterator>;
+
     IteratorRange(Iterator begin, Iterator end)
         : m_begin(WTFMove(begin))
         , m_end(WTFMove(end))
@@ -39,8 +41,10 @@
     {
     }
 
-    Iterator begin() const { return m_begin; }
-    Iterator end() const { return m_end; }
+    auto begin() const { return m_begin; }
+    auto end() const { return m_end; }
+    auto rbegin() const { return reverse_iterator { m_end }; }
+    auto rend() const { return reverse_iterator { m_begin }; }
 
 private:
     Iterator m_begin;
@@ -94,3 +98,6 @@
 }
 
 } // namespace WTF
+
+using WTF::IteratorRange;
+using WTF::makeReversedRange;

Modified: trunk/Source/WebCore/ChangeLog (283807 => 283808)


--- trunk/Source/WebCore/ChangeLog	2021-10-08 16:32:02 UTC (rev 283807)
+++ trunk/Source/WebCore/ChangeLog	2021-10-08 16:37:05 UTC (rev 283808)
@@ -1,3 +1,23 @@
+2021-10-08  Antti Koivisto  <[email protected]>
+
+        Make WTF::IteratorRange reversible
+        https://bugs.webkit.org/show_bug.cgi?id=231415
+
+        Reviewed by Darin Adler.
+
+        Replace a custom range type with the new reversible IteratorRange.
+
+        * layout/integration/LayoutIntegrationInlineContent.cpp:
+        (WebCore::LayoutIntegration:: const):
+        (WebCore::LayoutIntegration::InlineContent::boxesForRect const): Deleted.
+        * layout/integration/LayoutIntegrationInlineContent.h:
+        (WebCore::LayoutIntegration::InlineContent::BoxRange::begin const): Deleted.
+        (WebCore::LayoutIntegration::InlineContent::BoxRange::end const): Deleted.
+        (WebCore::LayoutIntegration::InlineContent::BoxRange::rbegin const): Deleted.
+        (WebCore::LayoutIntegration::InlineContent::BoxRange::rend const): Deleted.
+        * layout/integration/LayoutIntegrationLineLayout.cpp:
+        (WebCore::LayoutIntegration::LineLayout::hitTest):
+
 2021-10-08  Youenn Fablet  <[email protected]>
 
         https://webrtc.github.io/samples/src/content/getusermedia/getdisplaymedia/ is broken on Webkit ToT

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationInlineContent.cpp (283807 => 283808)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationInlineContent.cpp	2021-10-08 16:32:02 UTC (rev 283807)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationInlineContent.cpp	2021-10-08 16:37:05 UTC (rev 283808)
@@ -47,7 +47,7 @@
     return boxes.size() > 1;
 };
 
-auto InlineContent::boxesForRect(const LayoutRect& rect) const -> BoxRange
+IteratorRange<const InlineDisplay::Box*> InlineContent::boxesForRect(const LayoutRect& rect) const
 {
     if (boxes.isEmpty())
         return { nullptr, nullptr };

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationInlineContent.h (283807 => 283808)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationInlineContent.h	2021-10-08 16:32:02 UTC (rev 283807)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationInlineContent.h	2021-10-08 16:37:05 UTC (rev 283808)
@@ -67,19 +67,8 @@
     
     const Line& lineForBox(const InlineDisplay::Box& box) const { return lines[box.lineIndex()]; }
 
-    struct BoxRange {
-        using reverse_iterator = std::reverse_iterator<const InlineDisplay::Box*>;
+    IteratorRange<const InlineDisplay::Box*> boxesForRect(const LayoutRect&) const;
 
-        const InlineDisplay::Box* rangeBegin;
-        const InlineDisplay::Box* rangeEnd;
-
-        auto begin() const { return rangeBegin; }
-        auto end() const { return rangeEnd; }
-        auto rbegin() const { return reverse_iterator { rangeEnd  }; }
-        auto rend() const { return reverse_iterator { rangeBegin }; }
-    };
-    BoxRange boxesForRect(const LayoutRect&) const;
-
     void shrinkToFit();
 
     const LineLayout& lineLayout() const { return *m_lineLayout; }

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.cpp (283807 => 283808)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.cpp	2021-10-08 16:32:02 UTC (rev 283807)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.cpp	2021-10-08 16:37:05 UTC (rev 283808)
@@ -537,7 +537,7 @@
     hitTestBoundingBox.moveBy(-accumulatedOffset);
     auto boxRange = m_inlineContent->boxesForRect(hitTestBoundingBox);
 
-    for (auto& box : WTF::makeReversedRange(boxRange)) {
+    for (auto& box : makeReversedRange(boxRange)) {
         auto& renderer = m_boxTree.rendererForLayoutBox(box.layoutBox());
 
         if (!box.isRootInlineBox() && is<RenderLayerModelObject>(renderer) && downcast<RenderLayerModelObject>(renderer).hasSelfPaintingLayer())

Modified: trunk/Tools/ChangeLog (283807 => 283808)


--- trunk/Tools/ChangeLog	2021-10-08 16:32:02 UTC (rev 283807)
+++ trunk/Tools/ChangeLog	2021-10-08 16:37:05 UTC (rev 283808)
@@ -1,3 +1,13 @@
+2021-10-08  Antti Koivisto  <[email protected]>
+
+        Make WTF::IteratorRange reversible
+        https://bugs.webkit.org/show_bug.cgi?id=231415
+
+        Reviewed by Darin Adler.
+
+        * TestWebKitAPI/Tests/WTF/IteratorRange.cpp:
+        (TestWebKitAPI::TEST):
+
 2021-10-08  Carlos Garcia Campos  <[email protected]>
 
         [WebDriver] Update w3c and selenium tests

Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/IteratorRange.cpp (283807 => 283808)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/IteratorRange.cpp	2021-10-08 16:32:02 UTC (rev 283807)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/IteratorRange.cpp	2021-10-08 16:37:05 UTC (rev 283808)
@@ -69,4 +69,43 @@
         EXPECT_EQ(value, expectedResults[index++]);
 }
 
+TEST(WTF_IteratorRange, MakeReversedRangeFromRange)
+{
+    Vector<int> intVector { 10, 11, 12, 13 };
+
+    auto range = IteratorRange { intVector.begin(), intVector.end() };
+
+    auto reversedRange = makeReversedRange(range);
+
+    EXPECT_EQ(reversedRange.begin(), intVector.rbegin());
+    EXPECT_EQ(reversedRange.end(), intVector.rend());
+
+    std::array<int, 4> expectedResults { { 13, 12, 11, 10 } };
+    size_t index = 0;
+
+    for (auto& value : reversedRange)
+        EXPECT_EQ(value, expectedResults[index++]);
+}
+
+TEST(WTF_IteratorRange, OneWayIterator)
+{
+    struct OneWayIterator {
+        int* ptr;
+
+        bool operator!=(const OneWayIterator& other) { return ptr != other.ptr; }
+        auto& operator*() const { return *ptr; }
+        void operator++() { ++ptr; }
+    };
+
+    Vector<int> intVector { 10, 11, 12, 13 };
+
+    auto range = IteratorRange { OneWayIterator { intVector.begin() }, OneWayIterator { intVector.end() } };
+
+    std::array<int, 4> expectedResults { { 10, 11, 12, 13 } };
+    size_t index = 0;
+
+    for (auto& value : range)
+        EXPECT_EQ(value, expectedResults[index++]);
+}
+
 } // namespace TestWebKitAPI
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to