diff --git a/storage/country_tree.hpp b/storage/country_tree.hpp index b469b0fae0..260532dd8c 100644 --- a/storage/country_tree.hpp +++ b/storage/country_tree.hpp @@ -180,16 +180,15 @@ public: /// \brief Checks all nodes in tree to find an equal one. If there're several equal nodes /// returns the first found. /// \returns a poiter item in the tree if found and nullptr otherwise. - void Find(TValue const & value, vector & found) const + void Find(TKey const & key, vector & found) const { found.clear(); - if (IsEqual(value, m_countryTree->Value())) + if (key == m_countryTree->Value().Name()) found.push_back(m_countryTree.get()); - auto const range = m_countryTreeHashTable.equal_range(value.Name()); - auto const end = m_countryTreeHashTable.end(); - if (range.first == end && range.second == end) + auto const range = m_countryTreeHashTable.equal_range(key); + if (range.first == range.second) return; for_each(range.first, range.second, @@ -199,10 +198,10 @@ public: }); } - Node const * const FindFirst(TValue const & value) const + Node const * const FindFirst(TKey const & key) const { vector found; - Find(value, found); + Find(key, found); if (found.empty()) return nullptr; return found[0]; @@ -213,10 +212,10 @@ public: /// When new countries.txt with unique ids will be added FindLeaf will be removed /// and Find will be used intead. /// @TODO(bykoianko) Remove this method on countries.txt update. - Node const * const FindFirstLeaf(TValue const & value) const + Node const * const FindFirstLeaf(TKey const & key) const { vector found; - Find(value, found); + Find(key, found); for (auto node : found) { @@ -229,8 +228,6 @@ public: size_t ChildrenCount() const { return m_countryTree->ChildrenCount(); } private: - static bool IsEqual(TValue const & v1, TValue const & v2) { return !(v1 < v2) && !(v2 < v1); } - /// @TODO(bykoianko) The root of the tree currently is processed in a special way. /// It's never deleted. Because of it it's necessary to work with the root in a special way. /// See SetCountriesContainerAttrs method for example. And CountryTree::Clear() method diff --git a/storage/storage.cpp b/storage/storage.cpp index 09effa9449..1b8637f8f1 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -79,7 +79,7 @@ void DeleteFromDiskWithIndexes(LocalCountryFile const & localFile, MapOptions op TCountryTreeNode const & LeafNodeFromCountryId(TCountryTree const & root, TCountryId const & countryId) { - TCountryTreeNode const * node = root.FindFirstLeaf(Country(countryId)); + TCountryTreeNode const * node = root.FindFirstLeaf(countryId); CHECK(node, ("Node with id =", countryId, "not found in country tree as a leaf.")); return *node; } @@ -321,14 +321,14 @@ Country const & Storage::CountryLeafByCountryId(TCountryId const & countryId) co Country const & Storage::CountryByCountryId(TCountryId const & countryId) const { - TCountryTreeNode const * node = m_countries.FindFirst(Country(countryId)); + TCountryTreeNode const * node = m_countries.FindFirst(countryId); CHECK(node, ("Node with id =", countryId, "not found in country tree.")); return node->Value(); } bool Storage::IsCoutryIdInCountryTree(TCountryId const & countryId) const { - return m_countries.FindFirst(Country(countryId)) != nullptr; + return m_countries.FindFirst(countryId) != nullptr; } TLocalAndRemoteSize Storage::CountrySizeInBytes(TCountryId const & countryId, MapOptions opt) const @@ -876,7 +876,7 @@ TCountriesVec Storage::FindAllIndexesByFile(TCountryId const & name) const // @TODO(bykoianko) This method should be rewritten. At list now name and the param of Find // have different types: string and TCountryId. TCountriesVec result; - if (m_countries.FindFirst(Country(name))) + if (m_countries.FindFirst(name)) result.push_back(name); return result; } @@ -1119,7 +1119,7 @@ void Storage::GetChildren(TCountryId const & parent, TCountriesVec & childrenId) { ASSERT_THREAD_CHECKER(m_threadChecker, ()); - TCountryTreeNode const * const parentNode = m_countries.FindFirst(Country(parent)); + TCountryTreeNode const * const parentNode = m_countries.FindFirst(parent); if (parentNode == nullptr) { ASSERT(false, ("TCountryId =", parent, "not found in m_countries.")); @@ -1149,7 +1149,7 @@ void Storage::GetChildrenInGroups(TCountryId const & parent, { ASSERT_THREAD_CHECKER(m_threadChecker, ()); - TCountryTreeNode const * const parentNode = m_countries.FindFirst(Country(parent)); + TCountryTreeNode const * const parentNode = m_countries.FindFirst(parent); if (parentNode == nullptr) { ASSERT(false, ("TCountryId =", parent, "not found in m_countries.")); @@ -1213,7 +1213,7 @@ void Storage::DownloadNode(TCountryId const & countryId) { ASSERT_THREAD_CHECKER(m_threadChecker, ()); - TCountryTreeNode const * const node = m_countries.FindFirst(Country(countryId)); + TCountryTreeNode const * const node = m_countries.FindFirst(countryId); if (!node) return; @@ -1231,7 +1231,7 @@ void Storage::DeleteNode(TCountryId const & countryId) { ASSERT_THREAD_CHECKER(m_threadChecker, ()); - TCountryTreeNode const * const node = m_countries.FindFirst(Country(countryId)); + TCountryTreeNode const * const node = m_countries.FindFirst(countryId); if (!node) return; @@ -1293,7 +1293,7 @@ void Storage::GetNodeAttrs(TCountryId const & countryId, NodeAttrs & nodeAttrs) ASSERT_THREAD_CHECKER(m_threadChecker, ()); vector nodes; - m_countries.Find(Country(countryId), nodes); + m_countries.Find(countryId, nodes); CHECK(!nodes.empty(), ()); // If nodes.size() > 1 countryId corresponds to a disputed territories. // In that case it's guaranteed that most of attributes are equal for diff --git a/storage/storage.hpp b/storage/storage.hpp index 3dc7d88d7b..3a2037acde 100644 --- a/storage/storage.hpp +++ b/storage/storage.hpp @@ -526,7 +526,7 @@ bool HasCountryId(TCountriesVec const & sortedCountryIds, TCountryId const & cou template void Storage::ForEachInSubtree(TCountryId const & root, ToDo && toDo) const { - TCountryTreeNode const * const rootNode = m_countries.FindFirst(Country(root)); + TCountryTreeNode const * const rootNode = m_countries.FindFirst(root); if (rootNode == nullptr) { ASSERT(false, ("TCountryId =", root, "not found in m_countries.")); @@ -564,7 +564,7 @@ template void Storage::ForEachAncestorExceptForTheRoot(TCountryId const & countryId, ToDo && toDo) const { vector nodes; - m_countries.Find(Country(countryId), nodes); + m_countries.Find(countryId, nodes); if (nodes.empty()) { ASSERT(false, ("TCountryId =", countryId, "not found in m_countries."));