forked from organicmaps/organicmaps
Optimized Write function to avoid multiple vector reallocation.
This commit is contained in:
parent
bb1ad91155
commit
9434abdd15
1 changed files with 14 additions and 2 deletions
|
@ -49,9 +49,21 @@ public:
|
|||
|
||||
inline void Write(void const * p, size_t size)
|
||||
{
|
||||
if (m_Pos + size > m_Data.size())
|
||||
intptr_t freeSize = m_Data.size() - m_Pos;
|
||||
if (freeSize < 0)
|
||||
{
|
||||
m_Data.resize(m_Pos + size);
|
||||
memcpy(((uint8_t*)m_Data.data()) + m_Pos, p, size);
|
||||
freeSize = size;
|
||||
}
|
||||
|
||||
memcpy(&m_Data[m_Pos], p, min(size, static_cast<size_t>(freeSize)));
|
||||
|
||||
if (size > freeSize)
|
||||
{
|
||||
uint8_t const * it = reinterpret_cast<uint8_t const *>(p);
|
||||
m_Data.insert(m_Data.end(), it + freeSize, it + size);
|
||||
}
|
||||
|
||||
m_Pos += size;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue