From 1203fdf0cab9ede779d8994c508c213bd84f96f2 Mon Sep 17 00:00:00 2001 From: Juan Antonio Date: Sat, 9 Dec 2023 01:27:44 +0100 Subject: [PATCH] Use stepping instead of branching using modulus Modulus operations are very costly and generally should be avoided. They also take a few bytes. This version is actually a quite faster. --- app/spectrum.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/spectrum.c b/app/spectrum.c index c8af382bd..a437ffdd8 100644 --- a/app/spectrum.c +++ b/app/spectrum.c @@ -944,14 +944,14 @@ static void RenderStill() { const uint8_t METER_PAD_LEFT = 3; - for (int i = 0; i < 121; i++) { - if (i % 10 == 0) { - gFrameBuffer[2][i + METER_PAD_LEFT] = 0b01110000; - } else if (i % 5 == 0) { - gFrameBuffer[2][i + METER_PAD_LEFT] = 0b00110000; - } else { - gFrameBuffer[2][i + METER_PAD_LEFT] = 0b00010000; - } + memset(&gFrameBuffer[2][METER_PAD_LEFT], 0b00010000, 121); + + for (int i = 0; i < 121; i+=5) { + gFrameBuffer[2][i + METER_PAD_LEFT] = 0b00110000; + } + + for (int i = 0; i < 121; i+=10) { + gFrameBuffer[2][i + METER_PAD_LEFT] = 0b01110000; } uint8_t x = Rssi2PX(scanInfo.rssi, 0, 121);