From 8988dce93d718bfd6cf324c9fac25ec096bf6002 Mon Sep 17 00:00:00 2001 From: MacDue Date: Mon, 27 May 2024 11:40:02 +0100 Subject: [PATCH] LibGfx: Add early bounds checking to `accumulate_non_zero_scanline()` Nonzero fills are much more common (as the default fill rule), so if this does result in any speed-up it makes sense to do it here too. --- Userland/Libraries/LibGfx/EdgeFlagPathRasterizer.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibGfx/EdgeFlagPathRasterizer.cpp b/Userland/Libraries/LibGfx/EdgeFlagPathRasterizer.cpp index ffde816fa89..6d79aa825fe 100644 --- a/Userland/Libraries/LibGfx/EdgeFlagPathRasterizer.cpp +++ b/Userland/Libraries/LibGfx/EdgeFlagPathRasterizer.cpp @@ -323,13 +323,15 @@ template auto EdgeFlagPathRasterizer::accumulate_non_zero_scanline(EdgeExtent edge_extent, auto init, auto sample_callback) { NonZeroAcc acc = init; + VERIFY(edge_extent.min_x >= 0); + VERIFY(edge_extent.max_x < static_cast(m_scanline.size())); for (int x = edge_extent.min_x; x <= edge_extent.max_x; x += 1) { - if (auto edges = m_scanline[x]) { + if (auto edges = m_scanline.data()[x]) { // We only need to process the windings when we hit some edges. for (auto y_sub = 0u; y_sub < SamplesPerPixel; y_sub++) { auto subpixel_bit = 1 << y_sub; if (edges & subpixel_bit) { - auto winding = m_windings[x].counts[y_sub]; + auto winding = m_windings.data()[x].counts[y_sub]; auto previous_winding_count = acc.winding.counts[y_sub]; acc.winding.counts[y_sub] += winding; // Toggle fill on change to/from zero. @@ -339,8 +341,8 @@ auto EdgeFlagPathRasterizer::accumulate_non_zero_scanline(EdgeE } } sample_callback(x, acc.sample); - m_scanline[x] = 0; - m_windings[x] = {}; + m_scanline.data()[x] = 0; + m_windings.data()[x] = {}; } return acc; }