mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-08 00:00:26 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e5c7ef3b86 | ||
|
|
30bd7c1f21 | ||
|
|
923d927bd1 | ||
|
|
0b4185c716 | ||
|
|
e158160418 | ||
|
|
4645f6ec4b |
+1
-1
@@ -19,7 +19,7 @@ matrix:
|
||||
#
|
||||
# This job will also build and deploy the docs to gh-pages.
|
||||
- env: TARGET=x86_64-unknown-linux-gnu
|
||||
rust: 1.10.0
|
||||
rust: 1.15.0
|
||||
after_success:
|
||||
- |
|
||||
pip install 'travis-cargo<0.2' --user &&
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
# 0.4.3 (April, 30, 2017)
|
||||
|
||||
* Fix Vec::advance_mut bug
|
||||
* Bump minimum Rust version to 1.15
|
||||
* Misc performance tweaks
|
||||
|
||||
# 0.4.2 (April, 5, 2017)
|
||||
|
||||
* Misc performance tweaks
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
|
||||
name = "bytes"
|
||||
version = "0.4.2"
|
||||
version = "0.4.3"
|
||||
license = "MIT"
|
||||
authors = ["Carl Lerche <[email protected]>"]
|
||||
description = "Types and traits for working with bytes"
|
||||
|
||||
+1
-1
@@ -713,7 +713,7 @@ impl BufMut for Vec<u8> {
|
||||
if cnt > remaining {
|
||||
// Reserve additional capacity, and ensure that the total length
|
||||
// will not overflow usize.
|
||||
self.reserve(cnt - remaining);
|
||||
self.reserve(cnt);
|
||||
}
|
||||
|
||||
self.set_len(len + cnt);
|
||||
|
||||
+32
-3
@@ -87,13 +87,13 @@ use std::sync::atomic::Ordering::{Relaxed, Acquire, Release, AcqRel};
|
||||
/// underlying memory slice and may not be mutated, `BytesMut` handles are
|
||||
/// guaranteed to be the only handle able to view that slice of memory. As such,
|
||||
/// `BytesMut` handles are able to mutate the underlying memory. Note that
|
||||
/// holding a unique view to a region of memory does not mean that there are not
|
||||
/// holding a unique view to a region of memory does not mean that there are no
|
||||
/// other `Bytes` and `BytesMut` handles with disjoint views of the underlying
|
||||
/// memory.
|
||||
///
|
||||
/// # Inline bytes.
|
||||
///
|
||||
/// As an opitmization, when the slice referenced by a `Bytes` or `BytesMut`
|
||||
/// As an optimization, when the slice referenced by a `Bytes` or `BytesMut`
|
||||
/// handle is small enough [1], `Bytes` will avoid the allocation by inlining
|
||||
/// the slice directly in the handle. In this case, a clone is no longer
|
||||
/// "shallow" and the data will be copied.
|
||||
@@ -1111,7 +1111,7 @@ impl BytesMut {
|
||||
/// buf.put(&[0; 64][..]);
|
||||
///
|
||||
/// let ptr = buf.as_ptr();
|
||||
/// let other = buf.drain();
|
||||
/// let other = buf.take();
|
||||
///
|
||||
/// assert!(buf.is_empty());
|
||||
/// assert_eq!(buf.capacity(), 64);
|
||||
@@ -1164,6 +1164,16 @@ impl BufMut for BytesMut {
|
||||
self.advance_mut(len);
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn put_u8(&mut self, n: u8) {
|
||||
self.inner.put_u8(n);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn put_i8(&mut self, n: i8) {
|
||||
self.put_u8(n as u8);
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoBuf for BytesMut {
|
||||
@@ -1463,6 +1473,25 @@ impl Inner {
|
||||
}
|
||||
}
|
||||
|
||||
/// Insert a byte into the next slot and advance the len by 1.
|
||||
#[inline]
|
||||
fn put_u8(&mut self, n: u8) {
|
||||
if self.is_inline() {
|
||||
let len = self.inline_len();
|
||||
assert!(len < INLINE_CAP);
|
||||
unsafe {
|
||||
*self.inline_ptr().offset(len as isize) = n;
|
||||
}
|
||||
self.set_inline_len(len + 1);
|
||||
} else {
|
||||
assert!(self.len < self.cap);
|
||||
unsafe {
|
||||
*self.ptr.offset(self.len as isize) = n;
|
||||
}
|
||||
self.len += 1;
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn len(&self) -> usize {
|
||||
if self.is_inline() {
|
||||
|
||||
+2
-2
@@ -29,12 +29,12 @@
|
||||
//! buf.put(&b"hello world"[..]);
|
||||
//! buf.put_u16::<BigEndian>(1234);
|
||||
//!
|
||||
//! let a = buf.drain();
|
||||
//! let a = buf.take();
|
||||
//! assert_eq!(a, b"hello world\x04\xD2"[..]);
|
||||
//!
|
||||
//! buf.put(&b"goodbye world"[..]);
|
||||
//!
|
||||
//! let b = buf.drain();
|
||||
//! let b = buf.take();
|
||||
//! assert_eq!(b, b"goodbye world"[..]);
|
||||
//!
|
||||
//! assert_eq!(buf.capacity(), 998);
|
||||
|
||||
@@ -49,6 +49,17 @@ fn test_put_u16() {
|
||||
assert_eq!(b"\x54\x21", &buf[..]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_vec_advance_mut() {
|
||||
// Regression test for carllerche/bytes#108.
|
||||
let mut buf = Vec::with_capacity(8);
|
||||
unsafe {
|
||||
buf.advance_mut(12);
|
||||
assert_eq!(buf.len(), 12);
|
||||
assert!(buf.capacity() >= 12, "capacity: {}", buf.capacity());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_clone() {
|
||||
let mut buf = BytesMut::with_capacity(100);
|
||||
|
||||
Reference in New Issue
Block a user