[generator:preprocess] Optimize system call lseek() usage

This commit is contained in:
Anatoly Serdtcev 2019-11-01 08:23:11 +03:00 committed by Sergey Yershov
parent 18701d6e43
commit 9a9585f212
2 changed files with 4 additions and 1 deletions

View file

@ -358,6 +358,7 @@ OSMElementCacheReader::OSMElementCacheReader(string const & name, bool preload,
// OSMElementCacheWriter ---------------------------------------------------------------------------
OSMElementCacheWriter::OSMElementCacheWriter(string const & name, bool preload)
: m_fileWriter(name, FileWriter::OP_WRITE_TRUNCATE, 10 * 1024 * 1024 /* bufferSize */)
, m_currOffset{m_fileWriter.Pos()}
, m_offsets(name + OFFSET_EXT)
, m_name(name)
, m_preload(preload)

View file

@ -175,7 +175,7 @@ public:
template <typename Value>
void Write(Key id, Value const & value)
{
m_offsets.Add(id, m_fileWriter.Pos());
m_offsets.Add(id, m_currOffset);
m_data.clear();
MemWriter<decltype(m_data)> w(m_data);
@ -185,12 +185,14 @@ public:
uint32_t sz = static_cast<uint32_t>(m_data.size());
m_fileWriter.Write(&sz, sizeof(sz));
m_fileWriter.Write(m_data.data(), sz);
m_currOffset += sizeof(sz) + sz;
}
void SaveOffsets();
protected:
BufferedFileWriter m_fileWriter;
uint64_t m_currOffset{0};
IndexFileWriter m_offsets;
std::string m_name;
std::vector<uint8_t> m_data;