minor speedup for 2D

* robustness: Segment::height() should never return 0
* Segment::XY(), Segment::virtualWidth() and Segment::virtualHeight() declared inline in fx.h. The compiler will always inline these functions now, avoiding overhead of call/return. "Knowing" the function body might also enable other optimizations.
--> up to 10% speedup in 2D effects.
This commit is contained in:
Frank
2023-05-26 23:12:49 +02:00
parent e2eb3e8ab4
commit 9cb6189611
3 changed files with 26 additions and 23 deletions

View File

@@ -537,19 +537,10 @@ void Segment::setPalette(uint8_t pal) {
}
// 2D matrix
uint16_t Segment::virtualWidth() const { // WLEDMM use fast types
uint_fast16_t groupLen = groupLength();
uint_fast16_t vWidth = ((transpose ? height() : width()) + groupLen - 1) / groupLen;
if (mirror) vWidth = (vWidth + 1) /2; // divide by 2 if mirror, leave at least a single LED
return vWidth;
}
uint16_t Segment::virtualHeight() const { // WLEDMM use fast types
uint_fast16_t groupLen = groupLength();
uint_fast16_t vHeight = ((transpose ? width() : height()) + groupLen - 1) / groupLen;
if (mirror_y) vHeight = (vHeight + 1) /2; // divide by 2 if mirror, leave at least a single LED
return vHeight;
}
//
// WLEDMM Segment::virtualWidth() and Segment::virtualHeight() are declared inline, see FX.h
//
uint16_t Segment::nrOfVStrips() const {
uint16_t vLen = 1;