diff --git a/src/sfizz/CCMap.h b/src/sfizz/CCMap.h index 34bf5b7c..6da8da03 100644 --- a/src/sfizz/CCMap.h +++ b/src/sfizz/CCMap.h @@ -6,7 +6,8 @@ #pragma once #include "LeakDetector.h" -#include +#include +#include namespace sfz { /** @@ -42,7 +43,7 @@ public: */ const ValueType& getWithDefault(int index) const noexcept { - auto it = container.find(index); + auto it = absl::c_find_if(container, [&](auto&& pair){ return pair.first == index; }); if (it == container.end()) { return defaultValue; } else { @@ -51,16 +52,20 @@ public: } /** - * @brief Get the value at index key or emplace a new one if not present + * @brief Get the value at index or emplace a new one if not present * - * @param key the index of the element + * @param index the index of the element * @return ValueType& */ - ValueType& operator[](const int& key) noexcept + ValueType& operator[](const int& index) noexcept { - if (!contains(key)) - container.emplace(key, defaultValue); - return container.operator[](key); + auto it = absl::c_find_if(container, [&](auto&& pair){ return pair.first == index; }); + if (it == container.end()) { + container.emplace_back(index, defaultValue); + return container.back().second; + } else { + return it->second; + } } /** @@ -70,13 +75,6 @@ public: * @return false */ inline bool empty() const { return container.empty(); } - /** - * @brief Returns the value at index with bounds checking (and possibly exceptions) - * - * @param index - * @return const ValueType& - */ - const ValueType& at(int index) const { return container.at(index); } /** * @brief Returns true if the container containers an element at index * @@ -84,14 +82,17 @@ public: * @return true * @return false */ - bool contains(int index) const noexcept { return container.find(index) != container.end(); } - typename std::map::iterator begin() { return container.begin(); } - typename std::map::const_iterator begin() const { return container.cbegin(); } - typename std::map::iterator end() { return container.end(); } - typename std::map::const_iterator end() const { return container.cend(); } + bool contains(int index) const noexcept + { + return absl::c_find_if(container, [&](auto&& pair){ return pair.first == index; }) != container.end(); + } + typename std::vector>::iterator begin() { return container.begin(); } + typename std::vector>::const_iterator begin() const { return container.cbegin(); } + typename std::vector>::iterator end() { return container.end(); } + typename std::vector>::const_iterator end() const { return container.cend(); } private: const ValueType defaultValue; - std::map container; + std::vector> container; LEAK_DETECTOR(CCMap); }; } diff --git a/src/sfizz/Region.cpp b/src/sfizz/Region.cpp index 94d0218e..9e2c162e 100644 --- a/src/sfizz/Region.cpp +++ b/src/sfizz/Region.cpp @@ -854,7 +854,7 @@ bool sfz::Region::registerCC(int ccNumber, uint8_t ccValue) noexcept if (!triggerOnCC) return false; - if (ccTriggers.contains(ccNumber) && ccTriggers.at(ccNumber).containsWithEnd(ccValue)) + if (ccTriggers.contains(ccNumber) && ccTriggers[ccNumber].containsWithEnd(ccValue)) return true; else return false;