From 841eeb158e1d43ba34e4ee629143e10a2c4505ff Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Thu, 18 Nov 2021 00:10:49 +1100 Subject: [PATCH] drivers/neopixel: Avoid heap alloc in fill(). Previously the use of `range(start,stop,step)` caused an allocation. Replace with while loop. Signed-off-by: Jim Mussared --- drivers/neopixel/neopixel.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/neopixel/neopixel.py b/drivers/neopixel/neopixel.py index 0032d36183..caa12dc845 100644 --- a/drivers/neopixel/neopixel.py +++ b/drivers/neopixel/neopixel.py @@ -36,10 +36,14 @@ class NeoPixel: def fill(self, v): b = self.buf - for i in range(self.bpp): + l = len(self.buf) + bpp = self.bpp + for i in range(bpp): c = v[i] - for j in range(self.ORDER[i], len(self.buf), self.bpp): + j = self.ORDER[i] + while j < l: b[j] = c + j += bpp def write(self): # BITSTREAM_TYPE_HIGH_LOW = 0