mirror of
https://github.com/fafhrd91/actix-net
synced 2024-11-23 22:51:07 +01:00
Improve bcodec encode performance (#157)
This commit is contained in:
parent
a67e38b4a0
commit
8d0bd7ce1c
@ -3,6 +3,7 @@
|
|||||||
## Unreleased - 2020-xx-xx
|
## Unreleased - 2020-xx-xx
|
||||||
* Use `.advance()` instead of `.split_to()`.
|
* Use `.advance()` instead of `.split_to()`.
|
||||||
* Upgrade `tokio-util` to `0.3`.
|
* Upgrade `tokio-util` to `0.3`.
|
||||||
|
* Improve `BytesCodec` `.encode()` performance
|
||||||
|
|
||||||
## [0.2.0] - 2019-12-10
|
## [0.2.0] - 2019-12-10
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use bytes::{BufMut, Bytes, BytesMut};
|
use bytes::{Bytes, BytesMut, Buf};
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
use super::{Decoder, Encoder};
|
use super::{Decoder, Encoder};
|
||||||
@ -12,9 +12,9 @@ pub struct BytesCodec;
|
|||||||
impl Encoder<Bytes> for BytesCodec {
|
impl Encoder<Bytes> for BytesCodec {
|
||||||
type Error = io::Error;
|
type Error = io::Error;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn encode(&mut self, item: Bytes, dst: &mut BytesMut) -> Result<(), Self::Error> {
|
fn encode(&mut self, item: Bytes, dst: &mut BytesMut) -> Result<(), Self::Error> {
|
||||||
dst.reserve(item.len());
|
dst.extend_from_slice(item.bytes());
|
||||||
dst.put(item);
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user