mirror of
https://github.com/msgpack/msgpack-python.git
synced 2026-02-07 02:09:59 +00:00
lang/c/msgpack: optimize zone::alloc()
git-svn-id: file:///Users/frsyuki/project/msgpack-git/svn/x@61 5a5092ae-2292-43ba-b2d5-dcab9c1a2731
This commit is contained in:
parent
a721837ed0
commit
4d13f614b6
4 changed files with 86 additions and 73 deletions
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
namespace msgpack {
|
||||
|
||||
|
||||
struct unpacker::context {
|
||||
context(zone* z)
|
||||
{
|
||||
|
|
@ -98,11 +99,13 @@ void unpacker::expand_buffer(size_t len)
|
|||
else { next_size = UNPACKER_INITIAL_BUFFER_SIZE; }
|
||||
while(next_size < len + m_used) { next_size *= 2; }
|
||||
|
||||
// FIXME realloc?
|
||||
void* tmp = malloc(next_size);
|
||||
void* tmp = realloc(m_buffer, next_size);
|
||||
if(!tmp) { throw std::bad_alloc(); }
|
||||
memcpy(tmp, m_buffer, m_used);
|
||||
free(m_buffer);
|
||||
m_buffer = tmp;
|
||||
//void* tmp = malloc(next_size);
|
||||
//if(!tmp) { throw std::bad_alloc(); }
|
||||
//memcpy(tmp, m_buffer, m_used);
|
||||
//free(m_buffer);
|
||||
|
||||
m_buffer = tmp;
|
||||
m_free = next_size - m_used;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue