diff --git a/interface.go b/interface.go index af26fce..cf8afb8 100644 --- a/interface.go +++ b/interface.go @@ -52,5 +52,6 @@ type Interface interface { Marshal(io.Writer) error ErrorOffset() int + Prealloc(uint) Reset() } diff --git a/vector.go b/vector.go index 977a7ce..98c14ba 100644 --- a/vector.go +++ b/vector.go @@ -249,7 +249,8 @@ func (vec *Vector) getNode(depth int) (node *Node, idx int) { node = &vec.nodes[n-1] } vec.nodeL++ - node.vptr, node.depth = vec.ptr(), depth + node.depth = depth + node.vptr = vec.ptr() node.key.vptr, node.val.vptr = node.vptr, node.vptr idx = vec.Len() - 1 node.idx = idx @@ -275,6 +276,13 @@ func (vec *Vector) ErrorOffset() int { return vec.errOff } +// Prealloc prepares space for further parse. +func (vec *Vector) Prealloc(size uint) { + if ul := uint(len(vec.nodes)); ul < size { + vec.nodes = append(vec.nodes, make([]Node, size-ul+1)...) + } +} + // Reset vector data. func (vec *Vector) Reset() { if vec.nodeL == 0 {