diff options
author | vng <viktor.govako@gmail.com> | 2011-02-05 13:07:25 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:11:40 +0300 |
commit | b47f03877f822432de20c2bd57adf8053a0f4339 (patch) | |
tree | 71dfafd5c8148e8e861b51fe5a9a675e5ada4ee2 /indexer/geometry_serialization.cpp | |
parent | 197bb2c3ade260730946691d735b5118318f19ed (diff) |
Better reserve logic in triangles decoding.
Diffstat (limited to 'indexer/geometry_serialization.cpp')
-rw-r--r-- | indexer/geometry_serialization.cpp | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/indexer/geometry_serialization.cpp b/indexer/geometry_serialization.cpp index 2b6a41b595..a672c89602 100644 --- a/indexer/geometry_serialization.cpp +++ b/indexer/geometry_serialization.cpp @@ -40,22 +40,30 @@ namespace serial void Encode(EncodeFunT fn, vector<m2::PointD> const & points, int64_t base, DeltasT & deltas) { + size_t const count = points.size(); + PointsT upoints; - upoints.reserve(points.size()); + upoints.reserve(count); transform(points.begin(), points.end(), back_inserter(upoints), &pts::D2U); + ASSERT ( deltas.empty(), () ); + deltas.reserve(count); (*fn)(upoints, pts::GetBasePoint(base), pts::GetMaxPoint(), deltas); } - void Decode(DecodeFunT fn, DeltasT const & deltas, int64_t base, OutPointsT & points) + void Decode(DecodeFunT fn, DeltasT const & deltas, int64_t base, OutPointsT & points, size_t reserveF/* = 1*/) { + size_t const count = deltas.size() * reserveF; + PointsT upoints; - upoints.reserve(deltas.size()); + upoints.reserve(count); (*fn)(deltas, pts::GetBasePoint(base), pts::GetMaxPoint(), upoints); - // Don't make reserve for points. It may be not empty. + // It is may be not empty, when storing triangles. + if (points.empty()) + points.reserve(count); transform(upoints.begin(), upoints.end(), back_inserter(points), &pts::U2D); } @@ -172,8 +180,6 @@ namespace serial size_t const count = deltas.size(); ASSERT_GREATER ( count, 2, () ); - points.reserve(3*count); - points.push_back(DecodeDelta(deltas[0], basePoint)); points.push_back(DecodeDelta(deltas[1], points.back())); points.push_back(DecodeDelta(deltas[2] >> 2, points.back())); |