From 463bc27312fcbaea34ddf8b964db548ea1d197fe Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Thu, 22 Feb 2024 19:45:34 +0200 Subject: [PATCH] lib/storage: avoid superflouos copy of block header data --- lib/storage/block_stream_reader.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/storage/block_stream_reader.go b/lib/storage/block_stream_reader.go index a8b61d84d..85bdda91b 100644 --- a/lib/storage/block_stream_reader.go +++ b/lib/storage/block_stream_reader.go @@ -223,15 +223,14 @@ func (bsr *blockStreamReader) readBlock() error { return fmt.Errorf("too short index data for reading block header at offset %d; got %d bytes; want %d bytes", bsr.prevIndexBlockOffset(), len(bsr.indexCursor), marshaledBlockHeaderSize) } - bsr.Block.headerData = append(bsr.Block.headerData[:0], bsr.indexCursor[:marshaledBlockHeaderSize]...) - bsr.indexCursor = bsr.indexCursor[marshaledBlockHeaderSize:] - tail, err := bsr.Block.bh.Unmarshal(bsr.Block.headerData) + tail, err := bsr.Block.bh.Unmarshal(bsr.indexCursor[:marshaledBlockHeaderSize]) if err != nil { return fmt.Errorf("cannot parse block header read from index data at offset %d: %w", bsr.prevIndexBlockOffset(), err) } if len(tail) > 0 { return fmt.Errorf("non-empty tail left after parsing block header at offset %d: %x", bsr.prevIndexBlockOffset(), tail) } + bsr.indexCursor = bsr.indexCursor[marshaledBlockHeaderSize:] bsr.blocksCount++ if bsr.blocksCount > bsr.ph.BlocksCount {