diff --git a/triedb/pathdb/history_index_block.go b/triedb/pathdb/history_index_block.go index a4393b97b5..7648b99226 100644 --- a/triedb/pathdb/history_index_block.go +++ b/triedb/pathdb/history_index_block.go @@ -380,25 +380,10 @@ func (b *blockWriter) full() bool { // // This function is safe to be called multiple times. func (b *blockWriter) finish() []byte { - var ( - restartsLen = len(b.restarts) - restartsOff = len(b.data) - extra = restartsLen*2 + 1 - buf []byte - ) - - if cap(b.data)-len(b.data) >= extra { - // Enough capacity, just reslice; data is already in place. - buf = b.data[:len(b.data)+extra] - } else { - // Not enough capacity, allocate and copy. - buf = make([]byte, len(b.data)+extra) - copy(buf, b.data) - } - + buf := make([]byte, len(b.restarts)*2+1) for i, restart := range b.restarts { - binary.BigEndian.PutUint16(buf[restartsOff+2*i:], restart) + binary.BigEndian.PutUint16(buf[2*i:], restart) } - buf[len(buf)-1] = byte(restartsLen) - return buf + buf[len(buf)-1] = byte(len(b.restarts)) + return append(b.data, buf...) }