lib/storage: avoid superflouos copy of block header data

This commit is contained in:
Aliaksandr Valialkin 2024-02-22 19:45:34 +02:00
parent 34aa25d681
commit 463bc27312
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB

View file

@ -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", 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.prevIndexBlockOffset(), len(bsr.indexCursor), marshaledBlockHeaderSize)
} }
bsr.Block.headerData = append(bsr.Block.headerData[:0], bsr.indexCursor[:marshaledBlockHeaderSize]...) tail, err := bsr.Block.bh.Unmarshal(bsr.indexCursor[:marshaledBlockHeaderSize])
bsr.indexCursor = bsr.indexCursor[marshaledBlockHeaderSize:]
tail, err := bsr.Block.bh.Unmarshal(bsr.Block.headerData)
if err != nil { if err != nil {
return fmt.Errorf("cannot parse block header read from index data at offset %d: %w", bsr.prevIndexBlockOffset(), err) return fmt.Errorf("cannot parse block header read from index data at offset %d: %w", bsr.prevIndexBlockOffset(), err)
} }
if len(tail) > 0 { if len(tail) > 0 {
return fmt.Errorf("non-empty tail left after parsing block header at offset %d: %x", bsr.prevIndexBlockOffset(), tail) 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++ bsr.blocksCount++
if bsr.blocksCount > bsr.ph.BlocksCount { if bsr.blocksCount > bsr.ph.BlocksCount {