From ebe47de0b2e0f35397cf137ae565b8042d81ccd2 Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Mon, 11 May 2020 00:14:31 +0200 Subject: [PATCH] LibGfx: Eliminate conditional branch in dither In theory, this should make dithering a teensy bit faster. --- Libraries/LibGfx/Painter.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Libraries/LibGfx/Painter.cpp b/Libraries/LibGfx/Painter.cpp index f9a11853eb..024d0b4345 100644 --- a/Libraries/LibGfx/Painter.cpp +++ b/Libraries/LibGfx/Painter.cpp @@ -147,10 +147,8 @@ void Painter::fill_rect_with_dither_pattern(const Rect& a_rect, Color color_a, C for (int i = 0; i < rect.height(); ++i) { for (int j = 0; j < rect.width(); ++j) { - if (i & 1) - dst[j] = (j & 1) ? color_a.value() : color_b.value(); - else - dst[j] = (j & 1) ? color_b.value() : color_a.value(); + bool checkboard_use_a = (i & 1) ^ (j & 1); + dst[j] = checkboard_use_a ? color_a.value() : color_b.value(); } dst += dst_skip; }