Fix BytesMut refcounting

This commit is contained in:
Carl Lerche
2016-11-22 10:31:17 -08:00
parent 2b796d40e9
commit 93c08064bb
2 changed files with 4 additions and 5 deletions
-1
View File
@@ -224,4 +224,3 @@ impl Clone for ByteBuf {
} }
} }
} }
+4 -4
View File
@@ -148,7 +148,7 @@ impl<'a> IntoBuf for &'a Bytes {
impl Clone for Bytes { impl Clone for Bytes {
fn clone(&self) -> Bytes { fn clone(&self) -> Bytes {
Bytes { inner: self.inner.clone() } Bytes { inner: self.inner.shallow_clone() }
} }
} }
@@ -253,7 +253,7 @@ impl BytesMut {
/// ///
/// Panics if `at > capacity` /// Panics if `at > capacity`
pub fn split_off(&mut self, at: usize) -> BytesMut { pub fn split_off(&mut self, at: usize) -> BytesMut {
let mut other = self.clone(); let mut other = self.shallow_clone();
other.set_start(at); other.set_start(at);
self.set_end(at); self.set_end(at);
@@ -273,7 +273,7 @@ impl BytesMut {
/// ///
/// Panics if `at > len` /// Panics if `at > len`
pub fn drain_to(&mut self, at: usize) -> BytesMut { pub fn drain_to(&mut self, at: usize) -> BytesMut {
let mut other = self.clone(); let mut other = self.shallow_clone();
other.set_end(at); other.set_end(at);
self.set_start(at); self.set_start(at);
@@ -357,7 +357,7 @@ impl BytesMut {
/// Increments the ref count. This should only be done if it is known that /// Increments the ref count. This should only be done if it is known that
/// it can be done safely. As such, this fn is not public, instead other /// it can be done safely. As such, this fn is not public, instead other
/// fns will use this one while maintaining the guarantees. /// fns will use this one while maintaining the guarantees.
fn clone(&self) -> BytesMut { fn shallow_clone(&self) -> BytesMut {
BytesMut { BytesMut {
mem: self.mem.clone(), mem: self.mem.clone(),
.. *self .. *self