From 8831c76fb42c02fed6227cc05fe9cd262b860cec Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Tue, 4 Jul 2023 16:22:19 +0200 Subject: [PATCH] restoreColorLossy small optimization minor optimizations that give up to 10% speedup in my tests * use "fast" integer types (where possible) * replaced _bri with _restaurationBri (no use of globals) --- wled00/bus_manager.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/wled00/bus_manager.h b/wled00/bus_manager.h index bb5df68e..e9d773d6 100644 --- a/wled00/bus_manager.h +++ b/wled00/bus_manager.h @@ -236,13 +236,13 @@ class BusDigital : public Bus { void * _busPtr = nullptr; const ColorOrderMap &_colorOrderMap; - inline uint32_t restoreColorLossy(uint32_t c, uint8_t _restaurationBri) { - if (_bri == 255) return c; + inline uint32_t restoreColorLossy(uint32_t c, uint_fast8_t _restaurationBri) { + if (_restaurationBri == 255) return c; uint8_t* chan = (uint8_t*) &c; - for (uint8_t i=0; i<4; i++) + for (uint_fast8_t i=0; i<4; i++) { - uint16_t val = chan[i]; + uint_fast16_t val = chan[i]; chan[i] = ((val << 8) + _restaurationBri) / (_restaurationBri + 1); //adding _bri slighly improves recovery / stops degradation on re-scale } return c;