Makuna / NeoPixelBus

An Arduino NeoPixel support library supporting a large variety of individually addressable LEDs. Please refer to the Wiki for more details. Please use the GitHub Discussions to ask questions as the GitHub Issues feature is used for bug tracking.
GNU Lesser General Public License v3.0
1.17k stars 257 forks source link

Use Native type for loops that have large interations to save code size #813

Open Makuna opened 1 month ago

Makuna commented 1 month ago

Is your feature request related to a problem? Please describe. WLED developers have found that using a native size type to the uC (ESP32 would be 32 bit) on loops can reduce code size.

Describe the solution you'd like Define a NeoPixelBus wide type like uintLoop_t and intLoop_t (alternate of uintNative_t or others?) that then get used throughout NeoPixelBus. They get defined based on the microcontrollers platforms size. (using int and unsigned int?)

Additional context This seems to be a bigger issue (using smaller size than the native uC size) for larger chips as they then need to inject code on every increment or test to convert a native register to the size the code defined.

blazoncek commented 1 month ago

Perhaps just size_t would do when you only need positive numbers.

EDIT: the issue (but that is generic) is that it is only guaranteed to have 16 bits at least. IMO if you do not need maximum range (i.e. INTxx_MAX) in your loops then it may be best to use native size which is (more often than not) int or unsigned.

blazoncek commented 1 month ago

https://en.cppreference.com/w/cpp/types/integer