Pre-allocate COM vector

This commit is contained in:
Blaz Kristan 2024-09-11 16:45:39 +02:00
parent b4315152e2
commit 5df1a223c2
3 changed files with 3 additions and 0 deletions

View File

@ -35,6 +35,7 @@ struct ColorOrderMap {
bool add(uint16_t start, uint16_t len, uint8_t colorOrder);
inline uint8_t count() const { return _mappings.size(); }
inline void reserve(size_t num) { _mappings.reserve(num); }
void reset() {
_mappings.clear();

View File

@ -244,6 +244,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
// read color order map configuration
JsonArray hw_com = hw[F("com")];
if (!hw_com.isNull()) {
BusManager::getColorOrderMap().reserve(std::min(hw_com.size(), (size_t)WLED_MAX_COLOR_ORDER_MAPPINGS));
for (JsonObject entry : hw_com) {
uint16_t start = entry["start"] | 0;
uint16_t len = entry["len"] | 0;

View File

@ -215,6 +215,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
}
//doInitBusses = busesChanged; // we will do that below to ensure all input data is processed
// we will not bother with pre-allocating ColorOrderMappings vector
for (int s = 0; s < WLED_MAX_COLOR_ORDER_MAPPINGS; s++) {
int offset = s < 10 ? 48 : 55;
char xs[4] = "XS"; xs[2] = offset+s; xs[3] = 0; //start LED