Skip to content

Commit

Permalink
perf: specialize slice extension in Datagram::encode
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire authored and djc committed May 9, 2023
1 parent 89b527c commit d08ad01
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions quinn-proto/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
ops::{Range, RangeInclusive},
};

use bytes::{Buf, BufMut, Bytes};
use bytes::{Buf, BufMut, Bytes, BytesMut};
use tinyvec::TinyVec;

use crate::{
Expand Down Expand Up @@ -853,13 +853,13 @@ impl FrameStruct for Datagram {
}

impl Datagram {
pub(crate) fn encode<W: BufMut>(&self, length: bool, out: &mut W) {
pub(crate) fn encode(&self, length: bool, out: &mut BytesMut) {
out.write(Type(*DATAGRAM_TYS.start() | u64::from(length))); // 1 byte
if length {
// Safe to unwrap because we check length sanity before queueing datagrams
out.write(VarInt::from_u64(self.data.len() as u64).unwrap()); // <= 8 bytes
}
out.put_slice(&self.data);
out.extend_from_slice(&self.data);
}

pub(crate) fn size(&self, length: bool) -> usize {
Expand Down

0 comments on commit d08ad01

Please sign in to comment.