@@ -987,7 +987,8 @@ void Segment::fade_out(uint8_t rate) const {
987987 if (!isActive ()) return ; // not active
988988 rate = (256 -rate) >> 1 ;
989989 const int mappedRate = 256 / (rate + 1 );
990- for (unsigned j = 0 ; j < vLength (); j++) {
990+ const size_t rlength = rawLength (); // calculate only once
991+ for (unsigned j = 0 ; j < rlength; j++) {
991992 uint32_t color = getPixelColorRaw (j);
992993 if (color == colors[1 ]) continue ; // already at target color
993994 for (int i = 0 ; i < 32 ; i += 8 ) {
@@ -1008,13 +1009,15 @@ void Segment::fade_out(uint8_t rate) const {
10081009// fades all pixels to secondary color
10091010void Segment::fadeToSecondaryBy (uint8_t fadeBy) const {
10101011 if (!isActive () || fadeBy == 0 ) return ; // optimization - no scaling to apply
1011- for (unsigned i = 0 ; i < vLength (); i++) setPixelColorRaw (i, color_blend (getPixelColorRaw (i), colors[1 ], fadeBy));
1012+ const size_t rlength = rawLength (); // calculate only once
1013+ for (unsigned i = 0 ; i < rlength; i++) setPixelColorRaw (i, color_blend (getPixelColorRaw (i), colors[1 ], fadeBy));
10121014}
10131015
10141016// fades all pixels to black using nscale8()
10151017void Segment::fadeToBlackBy (uint8_t fadeBy) const {
10161018 if (!isActive () || fadeBy == 0 ) return ; // optimization - no scaling to apply
1017- for (unsigned i = 0 ; i < vLength (); i++) setPixelColorRaw (i, color_fade (getPixelColorRaw (i), 255 -fadeBy));
1019+ const size_t rlength = rawLength (); // calculate only once
1020+ for (unsigned i = 0 ; i < rlength; i++) setPixelColorRaw (i, color_fade (getPixelColorRaw (i), 255 -fadeBy));
10181021}
10191022
10201023/*
0 commit comments