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

@@ -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