diff --git a/indexer/drawing_rule_def.hpp b/indexer/drawing_rule_def.hpp index 2c8ac62870..c564979042 100644 --- a/indexer/drawing_rule_def.hpp +++ b/indexer/drawing_rule_def.hpp @@ -20,16 +20,16 @@ int32_t constexpr kOverlaysMaxPriority = 10000; public: int m_scale = -1; int m_type = -1; - int m_index = -1; + size_t m_index = std::numeric_limits::max(); // an index to RulesHolder.m_dRules[] int m_priority = -1; bool m_hatching = false; Key() = default; - Key(int s, int t, int i) : m_scale(s), m_type(t), m_index(i), m_priority(-1) {} + Key(int s, int t, size_t i) : m_scale(s), m_type(t), m_index(i), m_priority(-1) {} bool operator==(Key const & r) const { - return (m_scale == r.m_scale && m_type == r.m_type && m_index == r.m_index); + return (m_index == r.m_index); } void SetPriority(int pr) { m_priority = pr; } diff --git a/indexer/drawing_rules.cpp b/indexer/drawing_rules.cpp index 993d05d7af..f26376d83f 100644 --- a/indexer/drawing_rules.cpp +++ b/indexer/drawing_rules.cpp @@ -35,36 +35,6 @@ namespace } } // namespace -void BaseRule::CheckCacheSize(size_t s) -{ - m_id1.resize(s); - MakeEmptyID(); -} - -uint32_t BaseRule::GetID(size_t threadSlot) const -{ - ASSERT(m_id1.size() > threadSlot, ()); - return m_id1[threadSlot]; -} - -void BaseRule::SetID(size_t threadSlot, uint32_t id) const -{ - ASSERT(m_id1.size() > threadSlot, ()); - m_id1[threadSlot] = id; -} - -void BaseRule::MakeEmptyID(size_t threadSlot) -{ - ASSERT(m_id1.size() > threadSlot, ()); - m_id1[threadSlot] = empty_id; -} - -void BaseRule::MakeEmptyID() -{ - for (size_t i = 0; i < m_id1.size(); ++i) - MakeEmptyID(i); -} - LineDefProto const * BaseRule::GetLine() const { return 0; @@ -118,15 +88,10 @@ RulesHolder::~RulesHolder() void RulesHolder::Clean() { - for (size_t i = 0; i < m_container.size(); ++i) - { - RuleVec & v = m_container[i]; - for (size_t j = 0; j < v.size(); ++j) - delete v[j]; - v.clear(); - } + for (size_t i = 0; i < m_dRules.size(); ++i) + delete m_dRules[i]; - m_rules.clear(); + m_dRules.clear(); m_colors.clear(); } @@ -135,29 +100,18 @@ Key RulesHolder::AddRule(int scale, rule_type_t type, BaseRule * p) ASSERT ( 0 <= scale && scale <= scales::GetUpperStyleScale(), (scale) ); ASSERT ( 0 <= type && type < count_of_rules, () ); - m_container[type].push_back(p); + m_dRules.push_back(p); + auto const index = m_dRules.size() - 1; + Key const k(scale, type, index); - vector & v = m_rules[scale][type]; - v.push_back(static_cast(m_container[type].size()-1)); - - int const ret = static_cast(v.size() - 1); - Key k(scale, type, ret); - ASSERT ( Find(k) == p, (ret) ); + ASSERT(Find(k) == p, (index)); return k; } BaseRule const * RulesHolder::Find(Key const & k) const { - RulesMap::const_iterator i = m_rules.find(k.m_scale); - if (i == m_rules.end()) return 0; - - vector const & v = (i->second)[k.m_type]; - - ASSERT ( k.m_index >= 0, (k.m_index) ); - if (static_cast(k.m_index) < v.size()) - return m_container[k.m_type][v[k.m_index]]; - else - return 0; + ASSERT_LESS(k.m_index, m_dRules.size(), ()); + return m_dRules[k.m_index]; } uint32_t RulesHolder::GetBgColor(int scale) const @@ -178,16 +132,6 @@ uint32_t RulesHolder::GetColor(std::string const & name) const return it->second; } -void RulesHolder::ClearCaches() -{ - ForEachRule([](BaseRule * p) { p->MakeEmptyID(); }); -} - -void RulesHolder::ResizeCaches(size_t s) -{ - ForEachRule([s](BaseRule * p) { p->CheckCacheSize(s); }); -} - namespace { RulesHolder & rules(MapStyle mapStyle) diff --git a/indexer/drawing_rules.hpp b/indexer/drawing_rules.hpp index 59a0f26ae8..91a99cb425 100644 --- a/indexer/drawing_rules.hpp +++ b/indexer/drawing_rules.hpp @@ -11,7 +11,6 @@ #include #include -#include #include #include #include @@ -30,24 +29,10 @@ namespace drule { class BaseRule { - mutable buffer_vector m_id1; - - std::unique_ptr m_selector; - public: - static uint32_t const empty_id = 0xFFFFFFFF; - BaseRule() = default; virtual ~BaseRule() = default; - void CheckCacheSize(size_t s); - - uint32_t GetID(size_t threadSlot) const; - void SetID(size_t threadSlot, uint32_t id) const; - - void MakeEmptyID(size_t threadSlot); - void MakeEmptyID(); - virtual LineDefProto const * GetLine() const; virtual AreaRuleProto const * GetArea() const; virtual SymbolRuleProto const * GetSymbol() const; @@ -61,34 +46,19 @@ namespace drule // Set runtime feature style selector void SetSelector(std::unique_ptr && selector); + + private: + std::unique_ptr m_selector; }; class RulesHolder { - // container of rules by type - using RuleVec = std::vector; - std::array m_container; - - /// scale -> array of rules by type -> index of rule in m_container - using RulesMap = std::map, count_of_rules>>; - RulesMap m_rules; - - /// background color for scales in range [0...scales::UPPER_STYLE_SCALE] - std::vector m_bgColors; - - std::unordered_map m_colors; - public: RulesHolder(); ~RulesHolder(); Key AddRule(int scale, rule_type_t type, BaseRule * p); - void Clean(); - - void ClearCaches(); - void ResizeCaches(size_t Size); - BaseRule const * Find(Key const & k) const; uint32_t GetBgColor(int scale) const; @@ -103,20 +73,19 @@ namespace drule template void ForEachRule(ToDo && toDo) { - for (auto const & rule : m_rules) - { - for (int j = 0; j < count_of_rules; ++j) - { - std::vector const & v = rule.second[j]; - for (size_t k = 0; k < v.size(); ++k) - toDo(m_container[j][v[k]]); - } - } + for (auto const dRule : m_dRules) + toDo(dRule); } private: void InitBackgroundColors(ContainerProto const & cp); void InitColors(ContainerProto const & cp); + void Clean(); + + /// background color for scales in range [0...scales::UPPER_STYLE_SCALE] + std::vector m_bgColors; + std::unordered_map m_colors; + std::vector m_dRules; }; RulesHolder & rules();