Skip to content

Commit c8b5531

Browse files
committed
Refactor Bytes to use an internal vtable
Bytes is a useful tool for managing multiple slices into the same region of memory, and the other things it used to have been removed to reduce complexity. The exact strategy for managing the multiple references is no longer hard-coded, but instead backing by a customizable vtable. - Removed ability to mutate the underlying memory from the `Bytes` type. - Removed the "inline" (SBO) mechanism in `Bytes`. The reduces a large amount of complexity, and improves performance when accessing the slice of bytes, since a branch is no longer needed to check if the data is inline. - Removed `Bytes` knowledge of `BytesMut` (`BytesMut` may grow that knowledge back at a future point.)
1 parent ebe9602 commit c8b5531

File tree

15 files changed

+2091
-2562
lines changed

15 files changed

+2091
-2562
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ serde = { version = "1.0", optional = true }
2828
either = { version = "1.5", default-features = false, optional = true }
2929

3030
[dev-dependencies]
31+
loom = "0.2.8"
3132
serde_test = "1.0"

ci/azure-cross-compile.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
cmd: test
2+
cmd: build
33
rust_version: stable
44

55
jobs:

ci/azure-tsan.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ jobs:
1818
1919
# Run address sanitizer
2020
RUSTFLAGS="-Z sanitizer=address" \
21-
cargo test --tests --target x86_64-unknown-linux-gnu
21+
cargo test --target x86_64-unknown-linux-gnu --test test_bytes --test test_buf --test test_buf_mut
2222
2323
# Run thread sanitizer
2424
RUSTFLAGS="-Z sanitizer=thread" \
25-
cargo test --tests --target x86_64-unknown-linux-gnu
25+
cargo test --target x86_64-unknown-linux-gnu --test test_bytes --test test_buf --test test_buf_mut
2626
displayName: TSAN / MSAN

ci/tsan

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ race:test::run_tests_console::*closure
1919
# Probably more fences in std.
2020
race:__call_tls_dtors
2121

22-
# `is_inline_or_static` is explicitly called concurrently without synchronization.
23-
# The safety explanation can be found in a comment.
24-
race:Inner::is_inline_or_static
25-
2622
# This ignores a false positive caused by `thread::park()`/`thread::unpark()`.
2723
# See: https://github.com/rust-lang/rust/pull/54806#issuecomment-436193353
2824
race:pthread_cond_destroy

src/buf/chain.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,15 @@ impl<T, U> Buf for Chain<T, U>
187187
n
188188
}
189189

190+
/*
190191
fn to_bytes(&mut self) -> crate::Bytes {
191192
let mut bytes: crate::BytesMut = self.a.to_bytes().try_mut()
192193
.unwrap_or_else(|bytes| bytes.into());
193194
194195
bytes.put(&mut self.b);
195196
bytes.freeze()
196197
}
198+
*/
197199
}
198200

199201
impl<T, U> BufMut for Chain<T, U>

src/buf/vec_deque.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,3 @@ impl Buf for VecDeque<u8> {
2020
self.drain(..cnt);
2121
}
2222
}
23-
24-
#[cfg(test)]
25-
mod tests {
26-
use super::*;
27-
28-
#[test]
29-
fn hello_world() {
30-
let mut buffer: VecDeque<u8> = VecDeque::new();
31-
buffer.extend(b"hello world");
32-
assert_eq!(11, buffer.remaining());
33-
assert_eq!(b"hello world", buffer.bytes());
34-
buffer.advance(6);
35-
assert_eq!(b"world", buffer.bytes());
36-
buffer.extend(b" piece");
37-
let mut out = [0; 11];
38-
buffer.copy_to_slice(&mut out);
39-
assert_eq!(b"world piece", &out[..]);
40-
}
41-
}

0 commit comments

Comments
 (0)