Skip to content

Commit

Permalink
Optimize the bytes encoding at node
Browse files Browse the repository at this point in the history
  • Loading branch information
jianoaix committed Jun 15, 2024
1 parent eb54a4e commit e698a56
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion node/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,11 @@ func (s *Store) DeleteKeys(ctx context.Context, keys *[][]byte) error {
//
// encodeChunks(chunks) = (len(chunks[0]), chunks[0], len(chunks[1]), chunks[1], ...)
func encodeChunks(chunks [][]byte) ([]byte, error) {
buf := bytes.NewBuffer(make([]byte, 0))
totalSize := 0
for _, chunk := range chunks {
totalSize += len(chunk) + 8 // Add size of uint64 for length
}
buf := bytes.NewBuffer(make([]byte, 0, totalSize))
for _, chunk := range chunks {
if err := binary.Write(buf, binary.LittleEndian, uint64(len(chunk))); err != nil {
return nil, err
Expand Down

0 comments on commit e698a56

Please sign in to comment.