const const const

small speedup by declaring some functions "const"
This commit is contained in:
Frank
2024-11-24 17:45:25 +01:00
parent 61c2ba98b7
commit ce8fc8930e
4 changed files with 8 additions and 8 deletions

View File

@@ -4763,7 +4763,7 @@ class AuroraWave {
alive = true;
}
CRGB getColorForLED(int ledIndex) {
CRGB getColorForLED(int ledIndex) const {
if(ledIndex < center - width || ledIndex > center + width) return 0; //Position out of range of this wave
CRGB rgb;
@@ -4818,7 +4818,7 @@ class AuroraWave {
}
};
bool stillAlive() {
bool stillAlive() const {
return alive;
};
};

View File

@@ -420,7 +420,7 @@ typedef struct Segment {
};
size_t _dataLen; // WLEDMM uint16_t is too small
static size_t _usedSegmentData; // WLEDMM uint16_t is too small
void setPixelColorXY_fast(int x, int y,uint32_t c, uint32_t scaled_col, int cols, int rows); // set relative pixel within segment with color - faster, but no error checking!!!
void setPixelColorXY_fast(int x, int y,uint32_t c, uint32_t scaled_col, int cols, int rows) const; // set relative pixel within segment with color - faster, but no error checking!!!
bool _isSimpleSegment = false; // simple = no grouping or spacing - mirror, transpose or reverse allowed
bool _isSuperSimpleSegment = false; // superSimple = no grouping or spacing, no mirror - only transpose or reverse allowed
@@ -606,7 +606,7 @@ typedef struct Segment {
// transition functions
void startTransition(uint16_t dur); // transition has to start before actual segment values change
void handleTransition(void);
uint16_t progress(void); //transition progression between 0-65535
uint16_t progress(void) const; //transition progression between 0-65535
// WLEDMM method inlined for speed (its called at each setPixelColor)
inline uint8_t currentBri(uint8_t briNew, bool useCct = false) {
@@ -621,7 +621,7 @@ typedef struct Segment {
uint8_t currentMode(uint8_t modeNew);
uint32_t currentColor(uint8_t slot, uint32_t colorNew);
CRGBPalette16 &loadPalette(CRGBPalette16 &tgt, uint8_t pal);
CRGBPalette16 &loadPalette(CRGBPalette16 &tgt, uint8_t pal) const;
void setCurrentPalette(void);
// 1D strip

View File

@@ -272,7 +272,7 @@ void Segment::startFrame(void) {
// Simplified version of Segment::setPixelColorXY - without error checking. Does not support grouping or spacing
// * expects scaled color (final brightness) as additional input parameter, plus segment virtualWidth() and virtualHeight()
void IRAM_ATTR __attribute__((hot)) Segment::setPixelColorXY_fast(int x, int y, uint32_t col, uint32_t scaled_col, int cols, int rows) //WLEDMM
void IRAM_ATTR __attribute__((hot)) Segment::setPixelColorXY_fast(int x, int y, uint32_t col, uint32_t scaled_col, int cols, int rows) const //WLEDMM
{
unsigned i = UINT_MAX;
bool sameColor = false;

View File

@@ -311,7 +311,7 @@ void Segment::setUpLeds() {
}
}
CRGBPalette16 &Segment::loadPalette(CRGBPalette16 &targetPalette, uint8_t pal) {
CRGBPalette16 &Segment::loadPalette(CRGBPalette16 &targetPalette, uint8_t pal) const {
static unsigned long _lastPaletteChange = millis() - 990000; // perhaps it should be per segment //WLEDMM changed init value to avoid pure orange after startup
static CRGBPalette16 randomPalette = CRGBPalette16(DEFAULT_COLOR);
static CRGBPalette16 prevRandomPalette = CRGBPalette16(CRGB(BLACK));
@@ -452,7 +452,7 @@ void Segment::startTransition(uint16_t dur) {
}
// transition progression between 0-65535
uint16_t IRAM_ATTR_YN Segment::progress() {
uint16_t IRAM_ATTR_YN Segment::progress() const {
if (!transitional || !_t) return 0xFFFFU;
unsigned long timeNow = millis();
if (timeNow - _t->_start > _t->_dur || _t->_dur == 0) return 0xFFFFU;