reserve space for put_slice

This commit is contained in:
Nikolay Kim 2021-06-27 10:26:00 +06:00
parent fa6cd65cfc
commit 53e9487357
3 changed files with 10 additions and 4 deletions

View file

@ -1,5 +1,9 @@
# Changes
## 0.1.2 (2021-06-27)
* Reserve space for put_slice
## 0.1.1 (2021-06-27)
* Add `ByteString::as_slice()` method

View file

@ -1,6 +1,6 @@
[package]
name = "ntex-bytes"
version = "0.1.1"
version = "0.1.2"
license = "MIT"
authors = ["Carl Lerche <me@carllerche.com>"]
description = "Types and traits for working with bytes (bytes crate fork)"
@ -15,6 +15,8 @@ edition = "2018"
serde = "1.0"
bytes = "1.0.1"
backtrace = "*"
[dev-dependencies]
serde_test = "1.0"
serde_json = "1.0"

View file

@ -1566,7 +1566,6 @@ impl BytesMut {
/// ```
#[inline]
pub fn extend_from_slice(&mut self, extend: &[u8]) {
self.reserve(extend.len());
self.put_slice(extend);
}
@ -1671,9 +1670,8 @@ impl BufMut for BytesMut {
#[inline]
fn put_slice(&mut self, src: &[u8]) {
assert!(self.remaining_mut() >= src.len());
let len = src.len();
self.reserve(len);
unsafe {
ptr::copy_nonoverlapping(
@ -1687,11 +1685,13 @@ impl BufMut for BytesMut {
#[inline]
fn put_u8(&mut self, n: u8) {
self.reserve(1);
self.inner.put_u8(n);
}
#[inline]
fn put_i8(&mut self, n: i8) {
self.reserve(1);
self.put_u8(n as u8);
}
}