diff --git a/base/base_tests/cache_test.cpp b/base/base_tests/cache_test.cpp index a035deaf2f..4435028ac1 100644 --- a/base/base_tests/cache_test.cpp +++ b/base/base_tests/cache_test.cpp @@ -7,14 +7,45 @@ namespace { +// This functor will be passed in Cache::ForEachValue by reference class SimpleFunctor { public: + SimpleFunctor() {} + void operator() (char c) { m_v.push_back(c); } + vector m_v; + +private: + DISALLOW_COPY(SimpleFunctor); +}; + +// This functor will be passed in Cache::ForEachValue by move ctor +class SimpleMovableFunctor +{ +public: + SimpleMovableFunctor(vector * v) : m_v(v) {} + + // movable + SimpleMovableFunctor(SimpleMovableFunctor && other) + { + m_v = other.m_v; + other.m_v = nullptr; + } + + void operator() (char c) + { + m_v->push_back(c); + } + +private: + vector * m_v; + + DISALLOW_COPY(SimpleMovableFunctor); }; double constexpr kEpsilon = 1e-6; @@ -121,3 +152,11 @@ UNIT_TEST(CacheSmoke_5) cache.ForEachValue(ref(f)); // f passed by reference TEST_EQUAL(f.m_v, vector(8, 0), ()); } + +UNIT_TEST(CacheSmoke_6) +{ + my::CacheWithStat cache(3); // it contains 2^3=8 elements + vector v; + cache.ForEachValue(SimpleMovableFunctor(&v)); + TEST_EQUAL(v, vector(8, 0), ()); +} diff --git a/base/cache.hpp b/base/cache.hpp index 625a373c46..3352534f34 100644 --- a/base/cache.hpp +++ b/base/cache.hpp @@ -123,7 +123,7 @@ namespace my { if (m_access == 0) return 0.0; - return (double)m_miss / (double)m_access; + return static_cast(m_miss) / static_cast(m_access); } uint32_t GetCacheSize() const { return m_cache.GetCacheSize(); } @@ -152,7 +152,7 @@ namespace my private: Cache m_cache; - uint32_t m_miss; - uint32_t m_access; + uint64_t m_miss; + uint64_t m_access; }; } diff --git a/routing/features_road_graph.hpp b/routing/features_road_graph.hpp index bc71e4d66c..6439f322f6 100644 --- a/routing/features_road_graph.hpp +++ b/routing/features_road_graph.hpp @@ -43,7 +43,11 @@ private: bool IsOneWay(FeatureType const & ft) const; double GetSpeedKMPHFromFt(FeatureType const & ft) const; + // Searches a feature RoadInfo in the cache, and if does not find then + // loads feature from the index and takes speed for the feature from the vehicle model. RoadInfo const & GetCachedRoadInfo(uint32_t featureId) const; + // Searches a feature RoadInfo in the cache, and if does not find then takes passed feature and speed. + // This version is used to prevent redundant feature loading when feature speed is known. RoadInfo const & GetCachedRoadInfo(uint32_t featureId, FeatureType & ft, double speedKMPH) const; diff --git a/routing/vehicle_model.cpp b/routing/vehicle_model.cpp index c4f5bcf194..c58e38ec41 100644 --- a/routing/vehicle_model.cpp +++ b/routing/vehicle_model.cpp @@ -171,8 +171,8 @@ double PedestrianModel::GetSpeed(FeatureType const & f) const if (IsFoot(types) && IsRoad(types)) return VehicleModel::GetSpeed(types); - else - return 0.0; + + return 0.0; } } // namespace routing