tiny optimization
* use bitmask operations in getBitFromArray, setBitInArray * make currentBri "const"
This commit is contained in:
@@ -616,7 +616,7 @@ typedef struct Segment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WLEDMM method inlined for speed (its called at each setPixelColor)
|
// 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();
|
uint32_t prog = progress();
|
||||||
if (prog < 0xFFFFU) { // progress() < 0xFFFFU implies that _t is valid (see progress() function)
|
if (prog < 0xFFFFU) { // progress() < 0xFFFFU implies that _t is valid (see progress() function)
|
||||||
if (useCct) return ((briNew * prog) + _t->_cctT * (0xFFFFU - prog)) >> 16;
|
if (useCct) return ((briNew * prog) + _t->_cctT * (0xFFFFU - prog)) >> 16;
|
||||||
|
|||||||
@@ -464,7 +464,7 @@ uint16_t IRAM_ATTR_YN Segment::progress() const {
|
|||||||
|
|
||||||
// WLEDMM Segment::currentBri() is declared inline, see FX.h
|
// WLEDMM Segment::currentBri() is declared inline, see FX.h
|
||||||
#if 0
|
#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;
|
uint32_t prog = (transitional && _t) ? progress() : 0xFFFFU;
|
||||||
if (transitional && _t && prog < 0xFFFFU) {
|
if (transitional && _t && prog < 0xFFFFU) {
|
||||||
if (useCct) return ((briNew * prog) + _t->_cctT * (0xFFFFU - prog)) >> 16;
|
if (useCct) return ((briNew * prog) + _t->_cctT * (0xFFFFU - prog)) >> 16;
|
||||||
|
|||||||
@@ -12,16 +12,16 @@
|
|||||||
// WLEDMM functions to get/set bits in an array - based on functions created by Brandon for GOL
|
// 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
|
// 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
|
inline bool getBitFromArray(const uint8_t* byteArray, size_t position) { // get bit value
|
||||||
size_t byteIndex = position / 8;
|
size_t byteIndex = position >> 3; // same as "position/8"
|
||||||
unsigned bitIndex = position % 8;
|
unsigned bitIndex = position & 0x0007; // last 3 bits
|
||||||
uint8_t byteValue = byteArray[byteIndex];
|
uint8_t byteValue = byteArray[byteIndex];
|
||||||
return (byteValue >> bitIndex) & 1;
|
return (byteValue >> bitIndex) & 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void setBitInArray(uint8_t* byteArray, size_t position, bool value) { // set bit - with error handling for nullptr
|
inline void setBitInArray(uint8_t* byteArray, size_t position, bool value) { // set bit - with error handling for nullptr
|
||||||
//if (byteArray == nullptr) return;
|
//if (byteArray == nullptr) return;
|
||||||
size_t byteIndex = position / 8;
|
size_t byteIndex = position >> 3;
|
||||||
unsigned bitIndex = position % 8;
|
unsigned bitIndex = position & 0x0007; // last 3 bits
|
||||||
if (value)
|
if (value)
|
||||||
byteArray[byteIndex] |= (1 << bitIndex);
|
byteArray[byteIndex] |= (1 << bitIndex);
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user