Skip to content

Commit

Permalink
[ul] optimize get_client_pdu to not allocate a Vec per reader buffer …
Browse files Browse the repository at this point in the history
…fill
  • Loading branch information
Enet4 committed Nov 2, 2024
1 parent 3a99d18 commit 4ef8046
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions ul/src/association/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ pub enum Error {
pub type Result<T, E = Error> = std::result::Result<T, E>;

/// Helper function to get a PDU from a reader.
///
///
/// Chunks of data are read into `read_buffer`,
/// which should be passed in subsequent calls
/// to receive more PDUs from the same stream.
Expand All @@ -171,11 +171,11 @@ where
let recv = reader
.fill_buf()
.context(ReadPduSnafu)
.context(ReceiveSnafu)?
.to_vec();
reader.consume(recv.len());
.context(ReceiveSnafu)?;
let bytes_read = recv.len();
read_buffer.extend_from_slice(&recv);

Check warning on line 176 in ul/src/association/client.rs

View workflow job for this annotation

GitHub Actions / Test (default) (stable)

this expression creates a reference which is immediately dereferenced by the compiler
ensure!(!recv.is_empty(), ConnectionClosedSnafu);
reader.consume(bytes_read);
ensure!(bytes_read != 0, ConnectionClosedSnafu);
};
Ok(msg)
}
Expand Down

0 comments on commit 4ef8046

Please sign in to comment.