const const const

adding hints for the compiler for optimization.
In case your custom build complains about "const", just remove the keyword. based on e82f38e277, but going further :-)

* "const" class functions : function does not modify any class attributes ( --> "this" becomes const)

* __attribute__((pure)) :  function return value depends only on the parameters and/or global variables. The function does not modify any global or static variables.
* __attribute__((const)) : function only examines arguments (no globals), and has no effects except the return value. This slightly more strict than "pure"
* hot: tells the compiler "this functions is called very often"
* cold: the opposite of hot
This commit is contained in:
Frank
2024-08-07 14:58:38 +02:00
parent 273154db76
commit 7f9da309c9
14 changed files with 148 additions and 145 deletions

View File

@@ -177,7 +177,7 @@ void WS2812FX::setUpMatrix() {
}
// absolute matrix version of setPixelColor(), without error checking
void IRAM_ATTR WS2812FX::setPixelColorXY_fast(int x, int y, uint32_t col) //WLEDMM: IRAM_ATTR conditionally
void IRAM_ATTR __attribute__((hot)) WS2812FX::setPixelColorXY_fast(int x, int y, uint32_t col) //WLEDMM: IRAM_ATTR conditionally
{
uint_fast16_t index = y * Segment::maxWidth + x;
if (index < customMappingSize) index = customMappingTable[index];
@@ -200,7 +200,7 @@ void IRAM_ATTR_YN WS2812FX::setPixelColorXY(int x, int y, uint32_t col) //WLEDMM
}
// returns RGBW values of pixel
uint32_t WS2812FX::getPixelColorXY(uint16_t x, uint16_t y) {
uint32_t __attribute__((hot)) WS2812FX::getPixelColorXY(uint16_t x, uint16_t y) const {
#ifndef WLED_DISABLE_2D
uint_fast16_t index = (y * Segment::maxWidth + x); //WLEDMM: use fast types
#else
@@ -239,7 +239,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 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) //WLEDMM
{
unsigned i = UINT_MAX;
bool sameColor = false;
@@ -406,7 +406,7 @@ void Segment::setPixelColorXY(float x, float y, uint32_t col, bool aa, bool fast
}
// returns RGBW values of pixel
uint32_t IRAM_ATTR_YN Segment::getPixelColorXY(int x, int y) {
uint32_t IRAM_ATTR_YN Segment::getPixelColorXY(int x, int y) const {
if (x<0 || y<0 || !isActive()) return 0; // not active or out-of range
if (ledsrgb) {
int i = XY(x,y);