Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
firelizzard18 committed Oct 16, 2024
1 parent 6b0685d commit 5d6d144
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 12 deletions.
4 changes: 2 additions & 2 deletions pkg/database/keyvalue/block/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"gitlab.com/accumulatenetwork/core/schema/pkg/binary"
)

var poolEncoder = pool.New[binary.Encoder]()
var poolDecoder = pool.New[binary.Decoder]()
var poolEncoder = binary.NewEncoderPool()
var poolDecoder = binary.NewDecoderPool()
var poolLocation = pool.New[recordLocation]()
var poolBuffer = binary.NewBufferPool()

Expand Down
6 changes: 0 additions & 6 deletions pkg/database/keyvalue/block/index_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ func (f *indexFile) get(hash [32]byte) (*recordLocation, bool) {
return nil, false
}

dec := poolDecoder.Get()
defer poolDecoder.Put(dec)

loc := poolLocation.Get()
offset := index * indexFileEntrySize
readLocation((*[32]byte)(data[offset+32:]), loc)
Expand All @@ -105,9 +102,6 @@ func (f *indexFile) forEach(fn func([32]byte, *recordLocation) error) error {
h := f.file.Acquire()
defer h.Release()

dec := poolDecoder.Get()
defer poolDecoder.Put(dec)

var hash [64]byte
loc := new(recordLocation)
rd := h.AcquireRange(0, 0)
Expand Down
3 changes: 1 addition & 2 deletions pkg/database/keyvalue/block/record_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,8 @@ func (f *recordFile) ReadHeader(l *recordLocation) (*recordEntry, error) {
rd := h.AcquireRange(l.Offset, l.Offset+l.HeaderLen)
defer rd.Release()

dec := poolDecoder.Get()
dec := poolDecoder.Get(rd, binary.LeaveTrailing())
defer poolDecoder.Put(dec)
dec.Reset(rd, binary.LeaveTrailing())

e := new(recordEntry)
err := e.UnmarshalBinaryV2(dec)
Expand Down
2 changes: 1 addition & 1 deletion pkg/database/keyvalue/block/record_file_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (s *recordFileSet) Close() error {
func (s *recordFileSet) Commit(view *databaseView, entries []*entryAndData) error {
rw := new(recordWriter)
rw.encBuf = poolBuffer.Get()
rw.enc = poolEncoder.Get()
rw.enc = poolEncoder.Get(rw.encBuf)
defer poolBuffer.Put(rw.encBuf)
defer poolEncoder.Put(rw.enc)

Expand Down
3 changes: 2 additions & 1 deletion pkg/database/keyvalue/block/record_iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package block

import (
"bytes"
stdbin "encoding/binary"
"errors"
"io"
Expand Down Expand Up @@ -66,7 +67,7 @@ func (it *recordFileIterator) Range(yield func(int, recordPos) bool) bool {
rd := it.file.file.AcquireRange(0, recordFileHeaderSize)
defer rd.Release()

dec := poolDecoder.Get()
dec := poolDecoder.Get(bytes.NewReader(nil))
defer poolDecoder.Put(dec)

var typ entryType
Expand Down

0 comments on commit 5d6d144

Please sign in to comment.