From 07473730dd0298194dc892bdd14d7bddb3d4b0e0 Mon Sep 17 00:00:00 2001 From: tatiana-yan Date: Mon, 29 Jul 2019 17:18:22 +0300 Subject: [PATCH] [search] Review fixes --- search/geocoder.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/search/geocoder.cpp b/search/geocoder.cpp index 9083e20c1c..02b17cbd24 100644 --- a/search/geocoder.cpp +++ b/search/geocoder.cpp @@ -314,6 +314,16 @@ size_t OrderCountries(boost::optional const & position, m2::RectD co return distance(infos.begin(), sep); } +unique_ptr GetWorldContext(DataSource const & dataSource) +{ + vector> infos; + dataSource.GetMwmsInfo(infos); + MwmSet::MwmHandle handle = indexer::FindWorld(dataSource, infos); + if (handle.IsAlive()) + return make_unique(move(handle)); + return {}; +} + #define TRACE(branch) \ m_resultTracer.CallMethod(ResultTracer::Branch::branch); \ SCOPE_GUARD(tracerGuard, [&] { m_resultTracer.LeaveMethod(ResultTracer::Branch::branch); }); @@ -621,15 +631,8 @@ void Geocoder::FillLocalityCandidates(BaseContext const & ctx, CBV const & filte void Geocoder::CacheWorldLocalities() { - vector> infos; - m_dataSource.GetMwmsInfo(infos); - - MwmSet::MwmHandle handle = indexer::FindWorld(m_dataSource, infos); - if (handle.IsAlive()) - { - auto context = make_unique(move(handle)); + if (auto context = GetWorldContext(m_dataSource)) UNUSED_VALUE(m_localitiesCache.Get(*context)); - } } void Geocoder::FillLocalitiesTable(BaseContext const & ctx) @@ -983,6 +986,7 @@ void Geocoder::WithPostcodes(BaseContext & ctx, Fn && fn) TRACE(WithPostcodes); size_t const maxPostcodeTokens = GetMaxNumTokensInPostcode(); + auto worldContext = GetWorldContext(m_dataSource); for (size_t startToken = 0; startToken != ctx.m_numTokens; ++startToken) { @@ -1011,12 +1015,8 @@ void Geocoder::WithPostcodes(BaseContext & ctx, Fn && fn) m_postcodes.Clear(); - vector> infos; - m_dataSource.GetMwmsInfo(infos); - MwmSet::MwmHandle handle = indexer::FindWorld(m_dataSource, infos); - if (handle.IsAlive()) + if (worldContext) { - auto worldContext = make_unique(move(handle)); m_postcodes.m_worldFeatures = RetrievePostcodeFeatures(*worldContext, TokenSlice(m_params, tokenRange)); }