codec: use advance over split_to when data is not needed (#2198)

This commit is contained in:
Markus Westerlind 2020-01-30 20:26:19 +01:00 committed by GitHub
parent 1eee6508fc
commit c3d56b85c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 4 deletions

View File

@ -7,7 +7,7 @@ use tokio::{
stream::Stream,
};
use bytes::BytesMut;
use bytes::{Buf, BytesMut};
use futures_core::ready;
use futures_sink::Sink;
use log::trace;
@ -239,8 +239,7 @@ where
.into()));
}
// TODO: Add a way to `bytes` to do this w/o returning the drained data.
let _ = pinned.buffer.split_to(n);
pinned.buffer.advance(n);
}
// Try flushing the underlying IO

View File

@ -494,7 +494,7 @@ impl LengthDelimitedCodec {
let num_skip = self.builder.get_num_skip();
if num_skip > 0 {
let _ = src.split_to(num_skip);
src.advance(num_skip);
}
// Ensure that the buffer has enough space to read the incoming