improve reuse of cached []byte buffer

master
Oliver Tonnhofer 2013-06-03 11:04:15 +02:00
parent 64da1ef0b0
commit 0237f72b27
1 changed files with 4 additions and 1 deletions

View File

@ -9,8 +9,11 @@ import (
func MarshalDeltaNodes(nodes []element.Node, buf []byte) []byte {
estimatedLength := len(nodes)*4*3 + binary.MaxVarintLen64
if len(buf) < estimatedLength {
if cap(buf) < estimatedLength {
buf = make([]byte, estimatedLength)
} else {
// resize slice to full capacity
buf = buf[:cap(buf)-1]
}
lastId := int64(0)