diff --git a/include/itertools.hpp b/include/itertools.hpp index 9de58c65..0c7986a4 100644 --- a/include/itertools.hpp +++ b/include/itertools.hpp @@ -35,18 +35,18 @@ ReversedIterable reversed(IterableT &&_iterable) { return {_iterable}; } -// A map from `std::string` keys to `ItemT` items, iterable in the order the items were inserted. -template +// A map from `KeyT` keys to `ItemT` items, iterable in the order the items were inserted. +template class InsertionOrderedMap { - std::deque list; // `deque` does not invalidate item references - std::unordered_map map; // Indexes into `list` + std::deque list; // `deque` does not invalidate item references + std::unordered_map map; // Indexes into `list` public: size_t size() const { return list.size(); } bool empty() const { return list.empty(); } - bool contains(std::string const &name) const { return map.find(name) != map.end(); } + bool contains(KeyT const &key) const { return map.find(key) != map.end(); } ItemT &operator[](size_t i) { return list[i]; } @@ -55,13 +55,13 @@ public: typename decltype(list)::const_iterator begin() const { return list.begin(); } typename decltype(list)::const_iterator end() const { return list.end(); } - ItemT &add(std::string const &name) { - map[name] = list.size(); + ItemT &add(KeyT const &key) { + map[key] = list.size(); return list.emplace_back(); } - ItemT &add(std::string const &name, ItemT &&value) { - map[name] = list.size(); + ItemT &add(KeyT const &key, ItemT &&value) { + map[key] = list.size(); list.emplace_back(std::move(value)); return list.back(); } @@ -71,8 +71,8 @@ public: return list.emplace_back(); } - std::optional findIndex(std::string const &name) const { - if (auto search = map.find(name); search != map.end()) { + std::optional findIndex(KeyT const &key) const { + if (auto search = map.find(key); search != map.end()) { return search->second; } return std::nullopt; diff --git a/src/asm/charmap.cpp b/src/asm/charmap.cpp index ab8ae611..5ac22fa8 100644 --- a/src/asm/charmap.cpp +++ b/src/asm/charmap.cpp @@ -88,7 +88,7 @@ bool forEachChar( return true; } -static InsertionOrderedMap charmaps; +static InsertionOrderedMap charmaps; static Charmap *currentCharmap; static std::stack charmapStack; diff --git a/src/asm/section.cpp b/src/asm/section.cpp index 50635128..f6ec4e74 100644 --- a/src/asm/section.cpp +++ b/src/asm/section.cpp @@ -47,7 +47,7 @@ struct SectionStackEntry { }; static Section *currentSection = nullptr; -static InsertionOrderedMap
sections; +static InsertionOrderedMap sections; static uint32_t curOffset; // Offset into the current section (see `sect_GetSymbolOffset`) diff --git a/src/link/section.cpp b/src/link/section.cpp index 7c711b76..d93e36c8 100644 --- a/src/link/section.cpp +++ b/src/link/section.cpp @@ -17,7 +17,7 @@ #include "link/main.hpp" #include "link/warning.hpp" -static InsertionOrderedMap> sections; +static InsertionOrderedMap> sections; void sect_ForEach(void (*callback)(Section &)) { for (std::unique_ptr
&ptr : sections) {