Skip to content

Commit

Permalink
CR fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
algorandskiy committed Aug 28, 2023
1 parent ac5ae65 commit 2cfde98
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 3 additions & 3 deletions data/transactions/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ var txEncodingPool = sync.Pool{
}

// getTxEncodingBuf returns a wrapped byte slice that can be used for encoding a
// temporary message. The byte slice has zero length but potentially
// non-zero capacity. The caller gets full ownership of the byte slice,
// temporary message. The byte slice length of encoded Transaction{} object.
// The caller gets full ownership of the byte slice,
// but is encouraged to return it using putEncodingBuf().
func getTxEncodingBuf() *txEncodingBuf {
buf := txEncodingPool.Get().(*txEncodingBuf)
Expand All @@ -221,7 +221,7 @@ func (tx Transaction) ID() Txid {
buf := getTxEncodingBuf()
enc := tx.MarshalMsg(buf.b)
if cap(enc) > cap(buf.b) {
// use a bigger buffer is New's estimate was too small
// use a bigger buffer as New's estimate was too small
buf.b = enc

Check warning on line 225 in data/transactions/transaction.go

View check run for this annotation

Codecov / codecov/patch

data/transactions/transaction.go#L225

Added line #L225 was not covered by tests
}
defer putTxEncodingBuf(buf)
Expand Down
5 changes: 4 additions & 1 deletion protocol/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,18 +288,21 @@ func (d *MsgpDecoderBytes) Remaining() int {
// encodingPool holds temporary byte slice buffers used for encoding messages.
var encodingPool = sync.Pool{
New: func() interface{} {
return &EncodingBuf{b: make([]byte, 0, 1024)}
return &EncodingBuf{b: make([]byte, 0)}

Check warning on line 291 in protocol/codec.go

View check run for this annotation

Codecov / codecov/patch

protocol/codec.go#L291

Added line #L291 was not covered by tests
},
}

// EncodingBuf is a wrapper for a byte slice that can be used for encoding
type EncodingBuf struct {
b []byte
}

// Bytes returns the underlying byte slice
func (eb *EncodingBuf) Bytes() []byte {
return eb.b

Check warning on line 302 in protocol/codec.go

View check run for this annotation

Codecov / codecov/patch

protocol/codec.go#L301-L302

Added lines #L301 - L302 were not covered by tests
}

// Update updates the underlying byte slice to the given one if its capacity exceeds the current one.
func (eb *EncodingBuf) Update(v []byte) *EncodingBuf {
if cap(eb.b) < cap(v) {
eb.b = v

Check warning on line 308 in protocol/codec.go

View check run for this annotation

Codecov / codecov/patch

protocol/codec.go#L306-L308

Added lines #L306 - L308 were not covered by tests
Expand Down

0 comments on commit 2cfde98

Please sign in to comment.