diff --git a/arena/arena.go b/arena/arena.go index ceec084..2ca98aa 100644 --- a/arena/arena.go +++ b/arena/arena.go @@ -3,26 +3,28 @@ package arena type Arena struct { buf []byte - size int + offset int } func NewArena(size int) *Arena { a := new(Arena) - a.size = size a.buf = make([]byte, size, size) + a.offset = 0 return a } func (a *Arena) Make(size int) []byte { - if a.size < size { + if len(a.buf) < size || len(a.buf)-a.offset < size { return make([]byte, size) - } else if len(a.buf) < size { - a.buf = make([]byte, a.size) } - b := a.buf[0:size] - a.buf = a.buf[size:] + b := a.buf[a.offset : size+a.offset] + a.offset += size return b } + +func (a *Arena) Reset() { + a.offset = 0 +}