forked from organicmaps/organicmaps
Better reserve logic in triangles decoding.
This commit is contained in:
parent
197bb2c3ad
commit
b47f03877f
2 changed files with 16 additions and 11 deletions
|
@ -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()));
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace serial
|
|||
void Encode(EncodeFunT fn, vector<m2::PointD> const & points, int64_t base, DeltasT & deltas);
|
||||
|
||||
typedef buffer_vector<m2::PointD, 32> OutPointsT;
|
||||
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);
|
||||
|
||||
template <class TSink>
|
||||
void SaveInner(EncodeFunT fn, vector<m2::PointD> const & points, int64_t base, TSink & sink)
|
||||
|
@ -70,7 +70,7 @@ namespace serial
|
|||
void const * LoadInner(DecodeFunT fn, void const * pBeg, size_t count, int64_t base, OutPointsT & points);
|
||||
|
||||
template <class TSource>
|
||||
void LoadOuter(DecodeFunT fn, TSource & src, int64_t base, OutPointsT & points)
|
||||
void LoadOuter(DecodeFunT fn, TSource & src, int64_t base, OutPointsT & points, size_t reserveF = 1)
|
||||
{
|
||||
uint32_t const count = ReadVarUint<uint32_t>(src);
|
||||
vector<char> buffer(count);
|
||||
|
@ -81,8 +81,7 @@ namespace serial
|
|||
deltas.reserve(count / 2);
|
||||
ReadVarUint64Array(p, p + count, MakeBackInsertFunctor(deltas));
|
||||
|
||||
points.reserve(deltas.size());
|
||||
Decode(fn, deltas, base, points);
|
||||
Decode(fn, deltas, base, points, reserveF);
|
||||
}
|
||||
|
||||
|
||||
|
@ -163,7 +162,7 @@ namespace serial
|
|||
int const count = ReadPrimitiveFromSource<uint8_t>(src);
|
||||
|
||||
for (int i = 0; i < count; ++i)
|
||||
LoadOuter(&DecodeTriangles, src, base, triangles);
|
||||
LoadOuter(&DecodeTriangles, src, base, triangles, 3);
|
||||
}
|
||||
//@}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue