mirror of https://github.com/SeanOMik/libki.git
util: Base BitStream buffer expansion on the current position rather than the buffer size
This commit is contained in:
parent
8706384803
commit
5183131b69
|
@ -3,6 +3,7 @@
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
namespace ki
|
namespace ki
|
||||||
{
|
{
|
||||||
|
@ -148,7 +149,7 @@ namespace ki
|
||||||
void BitStream::expand_buffer()
|
void BitStream::expand_buffer()
|
||||||
{
|
{
|
||||||
// Work out a new buffer size
|
// 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)
|
if (new_size < m_buffer_size)
|
||||||
new_size = std::numeric_limits<size_t>::max();
|
new_size = std::numeric_limits<size_t>::max();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue