tiny optimization

* use bitmask operations in getBitFromArray, setBitInArray
* make currentBri "const"
This commit is contained in:
Frank
2025-01-17 21:13:27 +01:00
parent 7bf7ac0c33
commit 2c0063dc5b
3 changed files with 6 additions and 6 deletions

View File

@@ -616,7 +616,7 @@ typedef struct Segment {
}
// WLEDMM method inlined for speed (its called at each setPixelColor)
[[gnu::hot]] inline uint8_t currentBri(uint8_t briNew, bool useCct = false) {
[[gnu::hot]] inline uint8_t currentBri(uint8_t briNew, bool useCct = false) const {
uint32_t prog = progress();
if (prog < 0xFFFFU) { // progress() < 0xFFFFU implies that _t is valid (see progress() function)
if (useCct) return ((briNew * prog) + _t->_cctT * (0xFFFFU - prog)) >> 16;

View File

@@ -464,7 +464,7 @@ uint16_t IRAM_ATTR_YN Segment::progress() const {
// WLEDMM Segment::currentBri() is declared inline, see FX.h
#if 0
uint8_t IRAM_ATTR_YN Segment::currentBri(uint8_t briNew, bool useCct) {
uint8_t IRAM_ATTR_YN Segment::currentBri(uint8_t briNew, bool useCct) const {
uint32_t prog = (transitional && _t) ? progress() : 0xFFFFU;
if (transitional && _t && prog < 0xFFFFU) {
if (useCct) return ((briNew * prog) + _t->_cctT * (0xFFFFU - prog)) >> 16;

View File

@@ -12,16 +12,16 @@
// WLEDMM functions to get/set bits in an array - based on functions created by Brandon for GOL
// toDo : make this a class that's completely defined in a header file
inline bool getBitFromArray(const uint8_t* byteArray, size_t position) { // get bit value
size_t byteIndex = position / 8;
unsigned bitIndex = position % 8;
size_t byteIndex = position >> 3; // same as "position/8"
unsigned bitIndex = position & 0x0007; // last 3 bits
uint8_t byteValue = byteArray[byteIndex];
return (byteValue >> bitIndex) & 1;
}
inline void setBitInArray(uint8_t* byteArray, size_t position, bool value) { // set bit - with error handling for nullptr
//if (byteArray == nullptr) return;
size_t byteIndex = position / 8;
unsigned bitIndex = position % 8;
size_t byteIndex = position >> 3;
unsigned bitIndex = position & 0x0007; // last 3 bits
if (value)
byteArray[byteIndex] |= (1 << bitIndex);
else