Skip to content

Commit

Permalink
perf: nocopy read binary
Browse files Browse the repository at this point in the history
  • Loading branch information
jayantxie committed May 24, 2024
1 parent a9249d4 commit 36515e4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions pkg/protocol/bthrift/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,7 @@ func (binaryProtocol) ReadString(buf []byte) (value string, length int, err erro
if size < 0 || int(size) > len(buf) {
return value, length, perrors.NewProtocolErrorWithType(thrift.INVALID_DATA, "[ReadString] the string size greater than buf length")
}
data := spanCache.Copy(buf[length : length+int(size)])
value = utils.SliceByteToString(data)
value = utils.SliceByteToString(buf[length : length+int(size)])
length += int(size)
return
}
Expand All @@ -484,7 +483,7 @@ func (binaryProtocol) ReadBinary(buf []byte) (value []byte, length int, err erro
if size < 0 || size > len(buf) {
return value, length, perrors.NewProtocolErrorWithType(thrift.INVALID_DATA, "[ReadBinary] the binary size greater than buf length")
}
value = spanCache.Copy(buf[length : length+size])
value = buf[length : length+size]
length += size
return
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/remote/codec/thrift/binary_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ func (p *BinaryProtocol) ByteBuffer() remote.ByteBuffer {

// next ...
func (p *BinaryProtocol) next(size int) ([]byte, error) {
buf, err := p.trans.Next(size)
buf, err := p.trans.ReadBinary(size)
if err != nil {
return buf, perrors.NewProtocolError(err)
}
Expand Down

0 comments on commit 36515e4

Please sign in to comment.