mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
GH-1713: Avoid unneeded reallocs in SerializationFormat::WriteData
This commit is contained in:
parent
2476e36634
commit
9c29c8ddfc
1 changed files with 9 additions and 1 deletions
|
@ -82,10 +82,18 @@ bool SerializationFormat::ReadData(void* b, size_t count)
|
|||
bool SerializationFormat::WriteData(const void* b, size_t count)
|
||||
{
|
||||
// Increase buffer if necessary.
|
||||
bool size_changed = false;
|
||||
while ( output_pos + count > output_size )
|
||||
{
|
||||
output_size *= GROWTH_FACTOR;
|
||||
size_changed = true;
|
||||
}
|
||||
|
||||
output = (char*)util::safe_realloc(output, output_size);
|
||||
// The glibc standard states explicitly that calling realloc with the same
|
||||
// size is a no-op, but the same claim can't be made on other platforms.
|
||||
// There's really no reason to do that though.
|
||||
if ( size_changed )
|
||||
output = (char*)util::safe_realloc(output, output_size);
|
||||
|
||||
memcpy(output + output_pos, b, count);
|
||||
output_pos += count;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue