Skip to content

Commit

Permalink
avoid extra data allocation during quic peer read
Browse files Browse the repository at this point in the history
  • Loading branch information
vanessaviolet committed Jun 20, 2024
1 parent 7e7a651 commit 35af34d
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions p2p/quic.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,9 @@ func (c *QuicClient) Receive() (*TransportMessage, error) {
if m.Size > TransportMessageMaxSize {
return nil, fmt.Errorf("quic receive invalid message size %d", m.Size)
}
for {
data := make([]byte, int(m.Size)-len(m.Data))
s, err := io.ReadFull(c.stream, data)
if err != nil {
return nil, err
}
m.Data = append(m.Data, data[:s]...)
if len(m.Data) == int(m.Size) {
break
}
}

m.Data = make([]byte, m.Size)
_, err = io.ReadFull(c.stream, m.Data)
return m, err
}

Expand Down

0 comments on commit 35af34d

Please sign in to comment.