diff options
author | tatiana-yan <tatiana.kondakova@gmail.com> | 2019-03-11 15:56:18 +0300 |
---|---|---|
committer | mpimenov <mpimenov@users.noreply.github.com> | 2019-03-11 18:33:49 +0300 |
commit | ac2fd8bff29686d50364385abaaac36a94398aa7 (patch) | |
tree | 96c259b70da2689d3de33689882e45ce49b2c444 /search | |
parent | c87cb978e62f1eb4850639abb299aba46d2e13f5 (diff) |
[search] Minor FeaturesLayerMatcher refactoring.
Diffstat (limited to 'search')
-rw-r--r-- | search/features_layer_matcher.cpp | 40 | ||||
-rw-r--r-- | search/features_layer_matcher.hpp | 11 |
2 files changed, 15 insertions, 36 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,46 +53,32 @@ 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); -} + auto entry = m_matchingStreetsCache.Get(houseId); + if (!entry.second) + return entry.first; -FeaturesLayerMatcher::Streets const & FeaturesLayerMatcher::GetNearbyStreets(uint32_t featureId) -{ FeatureType feature; - return GetNearbyStreetsImpl(featureId, feature); -} + if (!GetByIndex(houseId, feature)) + return kInvalidId; -FeaturesLayerMatcher::Streets const & FeaturesLayerMatcher::GetNearbyStreets(uint32_t featureId, - FeatureType & feature) -{ - return GetNearbyStreetsImpl(featureId, feature); + return GetMatchingStreet(feature); } -FeaturesLayerMatcher::Streets const & FeaturesLayerMatcher::GetNearbyStreetsImpl( - uint32_t featureId, FeatureType & feature) +FeaturesLayerMatcher::Streets const & FeaturesLayerMatcher::GetNearbyStreets(FeatureType & feature) { static FeaturesLayerMatcher::Streets const kEmptyStreets; - auto entry = m_nearbyStreetsCache.Get(featureId); + auto entry = m_nearbyStreetsCache.Get(feature.GetID().m_index); if (!entry.second) return entry.first; - if (!feature.GetID().IsValid() && !GetByIndex(featureId, feature)) - return kEmptyStreets; - auto & streets = entry.first; m_reverseGeocoder.GetNearbyStreets(feature, streets); 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<Street>; - 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 { |