Question about the colorutils.h code.  Why sometimes a variable is declared in a function

fastled-support
gplus
(Kasper Kamperman) #1

Question about the colorutils.h code.

Why sometimes a variable is declared in a function as CHSV and at other moments as const struct CHSV&?

Like in:
void fill_gradient( T* targetArray,
uint16_t startpos, CHSV startcolor,
uint16_t endpos, CHSV endcolor,
TGradientDirectionCode directionCode = SHORTEST_HUES )

void fill_gradient( T* targetArray, uint16_t numLeds, const CHSV& c1, const CHSV& c2,
TGradientDirectionCode directionCode = SHORTEST_HUES )

(Mark Kriegsman) #2

Most of them (all?) should be const references. The others are probably just oversights. I’ll review them. Thanks for spotting it.

Passing a const reference is generally more efficient. Passing an object is likely to force the object to be copied (pass by value).

(Kasper Kamperman) #3

Clear. Thanks for the explanation. I’ve found also another bug (I think) I posted that one as an issue in Github:

(Mark Kriegsman) #4

Thanks. Yeah. I think I had run into that one too; I appreciate the ticket!