Commit 49f34fbf authored by Max Kellermann's avatar Max Kellermann

DecoderBuffer: use NewVarSize()

parent fe6094a8
...@@ -21,8 +21,7 @@ ...@@ -21,8 +21,7 @@
#include "DecoderBuffer.hxx" #include "DecoderBuffer.hxx"
#include "DecoderAPI.hxx" #include "DecoderAPI.hxx"
#include "util/ConstBuffer.hxx" #include "util/ConstBuffer.hxx"
#include "util/VarSize.hxx"
#include <glib.h>
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
...@@ -43,24 +42,22 @@ struct DecoderBuffer { ...@@ -43,24 +42,22 @@ struct DecoderBuffer {
/** the actual buffer (dynamic size) */ /** the actual buffer (dynamic size) */
unsigned char data[sizeof(size_t)]; unsigned char data[sizeof(size_t)];
DecoderBuffer(Decoder *_decoder, InputStream &_is,
size_t _size)
:decoder(_decoder), is(&_is),
size(_size), length(0), consumed(0) {}
}; };
DecoderBuffer * DecoderBuffer *
decoder_buffer_new(Decoder *decoder, InputStream &is, decoder_buffer_new(Decoder *decoder, InputStream &is,
size_t size) size_t size)
{ {
DecoderBuffer *buffer = (DecoderBuffer *)
g_malloc(sizeof(*buffer) - sizeof(buffer->data) + size);
assert(size > 0); assert(size > 0);
buffer->decoder = decoder; return NewVarSize<DecoderBuffer>(sizeof(DecoderBuffer::data),
buffer->is = &is; size,
buffer->size = size; decoder, is, size);
buffer->length = 0;
buffer->consumed = 0;
return buffer;
} }
void void
...@@ -68,7 +65,7 @@ decoder_buffer_free(DecoderBuffer *buffer) ...@@ -68,7 +65,7 @@ decoder_buffer_free(DecoderBuffer *buffer)
{ {
assert(buffer != nullptr); assert(buffer != nullptr);
g_free(buffer); DeleteVarSize(buffer);
} }
bool bool
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment