Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'routing/geometry.cpp')
-rw-r--r--routing/geometry.cpp19
1 files changed, 12 insertions, 7 deletions
diff --git a/routing/geometry.cpp b/routing/geometry.cpp
index 23a41ff4ca..0cb7d20809 100644
--- a/routing/geometry.cpp
+++ b/routing/geometry.cpp
@@ -15,6 +15,10 @@ using namespace std;
namespace
{
+// @TODO(bykoianko) Consider setting cache size based on available memory.
+// Maximum road geometry cache size in items.
+size_t constexpr kRoadsCacheSize = 5000;
+
// GeometryLoaderImpl ------------------------------------------------------------------------------
class GeometryLoaderImpl final : public GeometryLoader
{
@@ -137,20 +141,21 @@ void RoadGeometry::Load(VehicleModelInterface const & vehicleModel, FeatureType
}
// Geometry ----------------------------------------------------------------------------------------
-Geometry::Geometry(unique_ptr<GeometryLoader> loader) : m_loader(move(loader))
+Geometry::Geometry(unique_ptr<GeometryLoader> loader)
+ : m_loader(move(loader))
+ , m_featureIdToRoad(make_unique<FifoCache<uint32_t, RoadGeometry>>(
+ kRoadsCacheSize,
+ [this](uint32_t featureId, RoadGeometry & road) { m_loader->Load(featureId, road); }))
{
CHECK(m_loader, ());
}
RoadGeometry const & Geometry::GetRoad(uint32_t featureId)
{
- auto const & it = m_roads.find(featureId);
- if (it != m_roads.cend())
- return it->second;
+ ASSERT(m_featureIdToRoad, ());
+ ASSERT(m_loader, ());
- RoadGeometry & road = m_roads[featureId];
- m_loader->Load(featureId, road);
- return road;
+ return m_featureIdToRoad->GetValue(featureId);
}
// static