util: Base BitStream buffer expansion on the current position rather than the buffer size

This commit is contained in:
Joshua Scott 2018-10-20 12:59:39 +01:00
parent 8706384803
commit 5183131b69
1 changed files with 2 additions and 1 deletions

View File

@ -3,6 +3,7 @@
#include <exception>
#include <cstring>
#include <stdexcept>
#include <math.h>
namespace ki
{
@ -148,7 +149,7 @@ namespace ki
void BitStream::expand_buffer()
{
// Work out a new buffer size
auto new_size = (m_buffer_size << 1) + 2;
auto new_size = (2 << (uint64_t)log2(m_position.get_byte())) + 2;
if (new_size < m_buffer_size)
new_size = std::numeric_limits<size_t>::max();