diff options
author | Constantin Shalnev <c.shalnev@corp.mail.ru> | 2015-06-23 18:56:54 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:52:27 +0300 |
commit | c0a5b3be8873f1abc02d93b6e334241fb83132d2 (patch) | |
tree | c18fcdbcd4d18cf4954ecda01e7c34be4a0f359f /routing/features_road_graph.cpp | |
parent | 6ed6bb77775a3e47d884af60224f4611f937ee86 (diff) |
Optimization: removed redundant copying and calculations
Diffstat (limited to 'routing/features_road_graph.cpp')
-rw-r--r-- | routing/features_road_graph.cpp | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/routing/features_road_graph.cpp b/routing/features_road_graph.cpp index 1b2494d404..678ae89be4 100644 --- a/routing/features_road_graph.cpp +++ b/routing/features_road_graph.cpp @@ -42,24 +42,22 @@ public: void operator()(FeatureType & ft) { - FeatureID const fID = ft.GetID(); - if (fID.m_mwmId != m_graph.GetMwmID()) - return; - - /// @todo remove overhead with type and speed checks (now speed loads in cache creation) // check type to skip not line objects - feature::TypesHolder types(ft); - if (types.GetGeoType() != feature::GEOM_LINE) + if (ft.GetFeatureType() != feature::GEOM_LINE) return; // skip roads with null speed - double const speed = m_graph.GetSpeedKMPHFromFt(ft); - if (speed <= 0.0) + double const speedKMPH = m_graph.GetSpeedKMPHFromFt(ft); + if (speedKMPH <= 0.0) + return; + + FeatureID const fID = ft.GetID(); + if (fID.m_mwmId != m_graph.GetMwmID()) return; // load feature from cache - IRoadGraph::RoadInfo const & ri = m_graph.GetCachedRoadInfo(fID.m_offset, ft, false /*fullLoad*/); - ASSERT_EQUAL(speed, ri.m_speedKMPH, ()); + IRoadGraph::RoadInfo const & ri = m_graph.GetCachedRoadInfo(fID.m_offset, true /*preload*/, ft, speedKMPH); + ASSERT_EQUAL(speedKMPH, ri.m_speedKMPH, ()); m_edgesLoader(fID.m_offset, ri); } @@ -82,13 +80,13 @@ void FeaturesRoadGraph::LoadFeature(uint32_t featureId, FeatureType & ft) const IRoadGraph::RoadInfo FeaturesRoadGraph::GetRoadInfo(uint32_t featureId) const { FeatureType ft; - return GetCachedRoadInfo(featureId, ft, true /*fullLoad*/); + return GetCachedRoadInfo(featureId, false /*preload*/, ft, 0.0 /*speedKMPH*/); } double FeaturesRoadGraph::GetSpeedKMPH(uint32_t featureId) const { FeatureType ft; - return GetCachedRoadInfo(featureId, ft, true /*fullLoad*/).m_speedKMPH; + return GetCachedRoadInfo(featureId, false /*preload*/, ft, 0.0 /*speedKMPH*/).m_speedKMPH; } double FeaturesRoadGraph::GetMaxSpeedKMPH() const @@ -117,29 +115,37 @@ double FeaturesRoadGraph::GetSpeedKMPHFromFt(FeatureType const & ft) const } IRoadGraph::RoadInfo const & FeaturesRoadGraph::GetCachedRoadInfo(uint32_t featureId, - FeatureType & ft, bool fullLoad) const + bool preload, + FeatureType & ft, + double speedKMPH) const { bool found = false; RoadInfo & ri = m_cache.Find(featureId, found); if (!found) { - if (fullLoad) - LoadFeature(featureId, ft); - else + if (preload) { // ft must be set ASSERT(featureId == ft.GetID().m_offset, ()); ft.ParseGeometry(FeatureType::BEST_GEOMETRY); } + else + { + LoadFeature(featureId, ft); + speedKMPH = GetSpeedKMPHFromFt(ft); + } ri.m_bidirectional = !IsOneWay(ft); - ri.m_speedKMPH = GetSpeedKMPHFromFt(ft); + ri.m_speedKMPH = speedKMPH; ft.SwapPoints(ri.m_points); + m_cacheMiss++; } m_cacheAccess++; + ASSERT_EQUAL(ri.m_speedKMPH, GetSpeedKMPHFromFt(ft), ()); + return ri; } |