From 044b8301fac996273bccfae44c100771b35e2274 Mon Sep 17 00:00:00 2001 From: vng Date: Sun, 9 Jan 2011 11:14:45 +0200 Subject: [PATCH] Built in ReadVarInt64Array for geometry loading. --- indexer/feature_impl.hpp | 48 ++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/indexer/feature_impl.hpp b/indexer/feature_impl.hpp index 4177719b66..9e63f87711 100644 --- a/indexer/feature_impl.hpp +++ b/indexer/feature_impl.hpp @@ -34,39 +34,60 @@ namespace feature template void WriteCells(vector & cells, TSink & sink) { + vector buffer; + MemWriter > writer(buffer); + for (size_t i = 0; i < cells.size(); ++i) - WriteVarInt(sink, i == 0 ? cells[0] : cells[i] - cells[i-1]); + WriteVarInt(writer, i == 0 ? cells[0] : cells[i] - cells[i-1]); + + uint32_t const count = static_cast(buffer.size()); + WriteVarUint(sink, count); + sink.Write(&buffer[0], count); } + class points_emitter + { + vector & m_points; + int64_t m_id; + + public: + points_emitter(vector & points, uint32_t count) + : m_points(points), m_id(0) + { + m_points.reserve(count / 2); + } + void operator() (int64_t id) + { + m_points.push_back(pts::ToPoint(m_id += id)); + } + }; + template void ReadPoints(vector & points, TSource & src) { - int64_t id = 0; - for (size_t i = 0; i < points.size(); ++i) - points[i] = pts::ToPoint(id += ReadVarInt(src)); + uint32_t const count = ReadVarUint(src); + vector buffer(count); + char * p = &buffer[0]; + src.Read(p, count); + + ReadVarInt64Array(p, p + count, points_emitter(points, count)); } } template void SavePoints(vector const & points, TSink & sink) { - uint32_t const count = points.size(); - ASSERT_GREATER(count, 1, ()); + ASSERT_GREATER(points.size(), 1, ()); vector cells; detail::TransformPoints(points, cells); - WriteVarUint(sink, count - 2); - detail::WriteCells(cells, sink); } template void LoadPoints(vector & points, TSource & src) { - uint32_t const count = ReadVarUint(src) + 2; - points.resize(count); - detail::ReadPoints(points, src); } @@ -80,17 +101,12 @@ namespace feature vector cells; detail::TransformPoints(triangles, cells); - WriteVarUint(sink, count / 3 - 1); - detail::WriteCells(cells, sink); } template void LoadTriangles(vector & points, TSource & src) { - uint32_t const count = 3 * (ReadVarUint(src) + 1); - points.resize(count); - detail::ReadPoints(points, src); }