From ac2fd8bff29686d50364385abaaac36a94398aa7 Mon Sep 17 00:00:00 2001 From: tatiana-yan Date: Mon, 11 Mar 2019 15:56:18 +0300 Subject: [PATCH] [search] Minor FeaturesLayerMatcher refactoring. --- search/features_layer_matcher.cpp | 54 +++++++++++-------------------- search/features_layer_matcher.hpp | 11 +++---- 2 files changed, 22 insertions(+), 43 deletions(-) diff --git a/search/features_layer_matcher.cpp b/search/features_layer_matcher.cpp index 56d442005b..49ec9d61b1 100644 --- a/search/features_layer_matcher.cpp +++ b/search/features_layer_matcher.cpp @@ -53,38 +53,24 @@ void FeaturesLayerMatcher::OnQueryFinished() uint32_t FeaturesLayerMatcher::GetMatchingStreet(uint32_t houseId) { - FeatureType feature; - return GetMatchingStreetImpl(houseId, feature); -} - -uint32_t FeaturesLayerMatcher::GetMatchingStreet(uint32_t houseId, FeatureType & houseFeature) -{ - return GetMatchingStreetImpl(houseId, houseFeature); -} - -FeaturesLayerMatcher::Streets const & FeaturesLayerMatcher::GetNearbyStreets(uint32_t featureId) -{ - FeatureType feature; - return GetNearbyStreetsImpl(featureId, feature); -} - -FeaturesLayerMatcher::Streets const & FeaturesLayerMatcher::GetNearbyStreets(uint32_t featureId, - FeatureType & feature) -{ - return GetNearbyStreetsImpl(featureId, feature); -} - -FeaturesLayerMatcher::Streets const & FeaturesLayerMatcher::GetNearbyStreetsImpl( - uint32_t featureId, FeatureType & feature) -{ - static FeaturesLayerMatcher::Streets const kEmptyStreets; - - auto entry = m_nearbyStreetsCache.Get(featureId); + auto entry = m_matchingStreetsCache.Get(houseId); if (!entry.second) return entry.first; - if (!feature.GetID().IsValid() && !GetByIndex(featureId, feature)) - return kEmptyStreets; + FeatureType feature; + if (!GetByIndex(houseId, feature)) + return kInvalidId; + + return GetMatchingStreet(feature); +} + +FeaturesLayerMatcher::Streets const & FeaturesLayerMatcher::GetNearbyStreets(FeatureType & feature) +{ + static FeaturesLayerMatcher::Streets const kEmptyStreets; + + auto entry = m_nearbyStreetsCache.Get(feature.GetID().m_index); + if (!entry.second) + return entry.first; auto & streets = entry.first; m_reverseGeocoder.GetNearbyStreets(feature, streets); @@ -92,7 +78,7 @@ FeaturesLayerMatcher::Streets const & FeaturesLayerMatcher::GetNearbyStreetsImpl return streets; } -uint32_t FeaturesLayerMatcher::GetMatchingStreetImpl(uint32_t houseId, FeatureType & houseFeature) +uint32_t FeaturesLayerMatcher::GetMatchingStreet(FeatureType & houseFeature) { // Check if this feature is modified - the logic will be different. string streetName; @@ -100,14 +86,10 @@ uint32_t FeaturesLayerMatcher::GetMatchingStreetImpl(uint32_t houseId, FeatureTy osm::Editor::Instance().GetEditedFeatureStreet(houseFeature.GetID(), streetName); // Check the cached result value. - auto entry = m_matchingStreetsCache.Get(houseId); + auto entry = m_matchingStreetsCache.Get(houseFeature.GetID().m_index); if (!edited && !entry.second) return entry.first; - // Load feature if needed. - if (!houseFeature.GetID().IsValid() && !GetByIndex(houseId, houseFeature)) - return kInvalidId; - uint32_t & result = entry.first; result = kInvalidId; @@ -119,7 +101,7 @@ uint32_t FeaturesLayerMatcher::GetMatchingStreetImpl(uint32_t houseId, FeatureTy } // Get nearby streets and calculate the resulting index. - auto const & streets = GetNearbyStreets(houseId, houseFeature); + auto const & streets = GetNearbyStreets(houseFeature); if (edited) { diff --git a/search/features_layer_matcher.hpp b/search/features_layer_matcher.hpp index 97c1dbaef9..574e3119ed 100644 --- a/search/features_layer_matcher.hpp +++ b/search/features_layer_matcher.hpp @@ -341,24 +341,21 @@ private: if (!loaded && !GetByIndex(houseId, feature)) continue; - if (GetMatchingStreet(houseId, feature) == streetId) + if (GetMatchingStreet(feature) == streetId) fn(houseId, streetId); } } } - // Returns id of a street feature corresponding to a |houseId|, or + // Returns id of a street feature corresponding to a |houseId|/|houseFeature|, or // kInvalidId if there're not such street. uint32_t GetMatchingStreet(uint32_t houseId); - uint32_t GetMatchingStreet(uint32_t houseId, FeatureType & houseFeature); - uint32_t GetMatchingStreetImpl(uint32_t houseId, FeatureType & houseFeature); + uint32_t GetMatchingStreet(FeatureType & houseFeature); using Street = ReverseGeocoder::Street; using Streets = std::vector; - Streets const & GetNearbyStreets(uint32_t featureId); - Streets const & GetNearbyStreets(uint32_t featureId, FeatureType & feature); - Streets const & GetNearbyStreetsImpl(uint32_t featureId, FeatureType & feature); + Streets const & GetNearbyStreets(FeatureType & feature); inline bool GetByIndex(uint32_t id, FeatureType & ft) const {