Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add specialized get_X impls for Bytes struct to reduce dead code #622

Open
wants to merge 63 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
74e7628
added bytes-specific get_X functions to reduce dead code
Walnut356 Aug 16, 2023
b49f3d1
added bytes-specific get_X tests
Walnut356 Aug 16, 2023
329acdb
added inlining for Bytes get_X functions
Walnut356 Aug 17, 2023
f6e110b
fixed formatting
Walnut356 Sep 24, 2023
300a0c5
Merge branch 'tokio-rs:master' into bytes_get
Walnut356 Dec 12, 2023
6194572
more direct get strategy and additional tests
Walnut356 Dec 12, 2023
f73c6c8
Simplify UninitSlice::as_uninit_slice_mut() logic (#644)
lucab Dec 28, 2023
dbbdb63
Use `self.` instead of `Self::` (#642)
braddunbar Dec 28, 2023
3bf6583
readme: add security policy (#649)
Darksonn Jan 3, 2024
fbc64bc
Update loom to 0.7 (#651)
taiki-e Jan 7, 2024
09214ba
Update CI config (#650)
taiki-e Jan 7, 2024
abb4a2e
BytesMut: Assert alignment of Shared (#652)
braddunbar Jan 19, 2024
0864aea
add `Bytes::is_unique` (#643)
Cyborus04 Jan 19, 2024
0ba3b4c
Remove unnecessary namespace qualifier (#660)
braddunbar Jan 28, 2024
9257a6e
Remove an unnecessary else branch (#662)
braddunbar Jan 28, 2024
e24587d
Remove unreachable else branch (#661)
braddunbar Jan 28, 2024
d2e7abd
refactor: make parameter mut in From<Vec> (#667)
braddunbar Jan 31, 2024
8bcac21
Restore commented tests (#665)
braddunbar Feb 6, 2024
47e8305
Use sub instead of offset (#668)
braddunbar Feb 6, 2024
c6972d6
Calculate original capacity only if necessary (#666)
braddunbar Feb 6, 2024
f586ffc
set_vec_pos does not need a second parameter (#672)
braddunbar Feb 6, 2024
1bcd212
get_vec_pos: use &self instead of &mut self (#670)
braddunbar Feb 6, 2024
4628927
Refactor split_at/split_to (#663)
braddunbar Feb 23, 2024
99584cc
Use Iterator from the prelude (#673)
braddunbar Mar 2, 2024
c5fae00
copy_to_bytes: Add panic section to docs (#676)
braddunbar Mar 3, 2024
7968f6f
Remove redundant reserve call (#674)
braddunbar Mar 4, 2024
ca00411
Remove commented tests for Bytes::unsplit (#677)
braddunbar Mar 4, 2024
536db06
Use ManuallyDrop instead of mem::forget (#675)
braddunbar Mar 14, 2024
ce8d8a0
chore: prepare bytes v1.6.0 (#681)
braddunbar Mar 22, 2024
0d4cc7f
Bytes: Use ManuallyDrop instead of mem::forget (#678)
braddunbar Apr 8, 2024
e4af486
Don't set `len` in `BytesMut::reserve` (#682)
braddunbar Apr 9, 2024
4eb62b9
Bytes::split_to - check fast path first (#689)
braddunbar Apr 10, 2024
b5fbfc3
perf: improve Bytes::copy_to_bytes (#688)
tisonkun Apr 10, 2024
327615e
test(benches): encloses bytes into `test::black_box` for clone benche…
wyfo Apr 11, 2024
4e2c9c0
Truncate tweaks (#694)
braddunbar Apr 17, 2024
9d3ec1c
Resize refactor (#696)
braddunbar Apr 24, 2024
ce09d7d
Bytes::split_off - check fast path first (#693)
braddunbar Apr 24, 2024
baa5053
Reuse capacity when possible in <BytesMut as Buf>::advance impl (#698)
paolobarbolini Apr 25, 2024
a8806c2
Improve BytesMut::split suggestion (#699)
paolobarbolini Apr 25, 2024
cb7f844
Tweak clear and truncate length modifications (#700)
Darksonn Apr 26, 2024
0c17e99
ci: silence unexpected-cfgs warnings due to `#[cfg(loom)]` (#703)
Darksonn May 5, 2024
86694b0
Add zero-copy make_mut (#695)
Sytten May 5, 2024
4950c50
Offset from (#705)
braddunbar May 11, 2024
caf520a
Fix iter tests to use the actual bytes IntoIter instead of std (#707)
paolobarbolini May 19, 2024
fa1daac
Change Bytes::make_mut to impl From<Bytes> for BytesMut (closes #709)…
nox May 28, 2024
7a5154b
Clarify how `BytesMut::zeroed` works and advantages to manual impl (#…
paolobarbolini Jun 21, 2024
8cc9407
Allow reclaiming the current allocation (#686)
shahn Jun 28, 2024
3443ca5
docs: clarify the behavior of `Buf::chunk` (#717)
vvvviiv Jul 9, 2024
9965a04
Remove unnecessary file (#719)
A5rocks Jul 10, 2024
6b4b0ed
Fix `Bytes::is_unique` when created from shared `BytesMut` (#718)
zyxw59 Jul 12, 2024
fd13c7d
chore: prepare bytes v1.6.1 (#720)
Darksonn Jul 13, 2024
f8c7b57
Merge 'v1.6.1' into 'master' (#721)
Darksonn Jul 13, 2024
03fdde9
chore: prepare v1.7.0 (#724)
mox692 Jul 31, 2024
f488be4
Revert "Reuse capacity when possible in <BytesMut as Buf>::advance im…
Darksonn Aug 1, 2024
dc4fb3e
chore: prepare bytes v1.7.1 (#727)
Darksonn Aug 1, 2024
ed7d5ff
test: ensure BytesMut::advance reduces capacity (#728)
camshaft Aug 2, 2024
291df5a
Fix double spaces in comments and doc comments (#731)
paolobarbolini Aug 19, 2024
79fb853
fix: apply sign extension when decoding int (#732)
paolobarbolini Aug 30, 2024
4b6d35d
added bytes-specific get_X functions to reduce dead code
Walnut356 Aug 16, 2023
50c4d2f
added bytes-specific get_X tests
Walnut356 Aug 16, 2023
2fb872e
more direct get strategy and additional tests
Walnut356 Dec 12, 2023
f7f3526
Merge branch 'bytes_get' of https://github.com/Walnut356/bytes into b…
Walnut356 Sep 1, 2024
b43c8c1
whoops
Walnut356 Sep 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 31 additions & 23 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:
push:
branches:
- master
schedule:
- cron: '0 2 * * 0'

env:
RUSTFLAGS: -Dwarnings
Expand All @@ -23,19 +25,19 @@ jobs:
name: rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update stable && rustup default stable
run: rustup update stable
- name: Check formatting
run: cargo fmt --all -- --check
run: cargo fmt --all --check

# TODO
# # Apply clippy lints
# clippy:
# name: clippy
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - uses: actions/checkout@v4
# - name: Apply clippy lints
# run: cargo clippy --all-features

Expand All @@ -48,11 +50,11 @@ jobs:
name: minrust
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Rust
run: rustup update 1.39.0 && rustup default 1.39.0
- uses: actions/checkout@v4
- name: Install cargo-hack
uses: taiki-e/install-action@cargo-hack
- name: Check
run: . ci/test-stable.sh check
run: cargo hack check --feature-powerset --optional-deps --rust-version

# Stable
stable:
Expand All @@ -65,23 +67,27 @@ jobs:
- windows-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install Rust
# --no-self-update is necessary because the windows environment cannot self-update rustup.exe.
run: rustup update stable --no-self-update && rustup default stable
run: rustup update stable --no-self-update
- name: Install cargo-hack
uses: taiki-e/install-action@cargo-hack
- name: Test
run: . ci/test-stable.sh test
run: ci/test-stable.sh test

# Nightly
nightly:
name: nightly
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update $nightly && rustup default $nightly
- name: Install cargo-hack
uses: taiki-e/install-action@cargo-hack
- name: Test
run: . ci/test-stable.sh test
run: ci/test-stable.sh test

# Run tests on some extra platforms
cross:
Expand All @@ -96,13 +102,14 @@ jobs:
- wasm32-unknown-unknown
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update stable && rustup default stable
run: rustup update stable
- name: Install cross
uses: taiki-e/install-action@cross
if: matrix.target != 'wasm32-unknown-unknown'
- name: cross build --target ${{ matrix.target }}
run: |
cargo install cross
cross build --target ${{ matrix.target }}
run: cross build --target ${{ matrix.target }}
if: matrix.target != 'wasm32-unknown-unknown'
# WASM support
- name: cargo build --target ${{ matrix.target }}
Expand All @@ -116,18 +123,19 @@ jobs:
name: tsan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update $nightly && rustup default $nightly
- name: Install rust-src
run: rustup component add rust-src
- name: ASAN / TSAN
run: . ci/tsan.sh
run: ci/tsan.sh

miri:
name: miri
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Miri
run: ci/miri.sh

Expand All @@ -136,7 +144,7 @@ jobs:
name: loom
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update $nightly && rustup default $nightly
- name: Loom tests
Expand All @@ -155,7 +163,7 @@ jobs:
- loom
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update $nightly && rustup default $nightly
- name: Build documentation
Expand Down
79 changes: 79 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,82 @@
# 1.7.1 (August 1, 2024)

This release reverts the following change due to a regression:

- Reuse capacity when possible in `<BytesMut as Buf>::advance` impl (#698)

The revert can be found at #726.

# 1.7.0 (July 31, 2024)

### Added

- Add conversion from `Bytes` to `BytesMut` (#695, #710)
- Add reclaim method without additional allocation (#686)

### Documented

- Clarify how `BytesMut::zeroed` works (#714)
- Clarify the behavior of `Buf::chunk` (#717)

### Changed

- Change length condition of `BytesMut::truncate`
- Reuse capacity when possible in `<BytesMut as Buf>::advance` impl (#698)
- Improve `must_use` suggestion of `BytesMut::split` (#699)

### Internal changes

- Use `ManuallyDrop` instead of `mem::forget` (#678)
- Don't set `len` in `BytesMut::reserve` (#682)
- Optimize `Bytes::copy_to_bytes` (#688)
- Refactor `BytesMut::truncate` (#694)
- Refactor `BytesMut::resize` (#696)
- Reorder assertion in `Bytes::split_to`, `Bytes::split_off` (#689, #693)
- Use `offset_from` in more places (#705)
- Correct the wrong usage of `IntoIter` (#707)

# 1.6.1 (July 13, 2024)

This release fixes a bug where `Bytes::is_unique` returns incorrect values when
the `Bytes` originates from a shared `BytesMut`. (#718)

# 1.6.0 (March 22, 2024)

### Added

- Add `Bytes::is_unique` (#643)

### Documented

- Fix changelog typo (#628)
- Fix some spelling mistakes (#633)
- Typo fix (#637)
- Fix broken links (#639)
- Add security policy (#649)

### Internal changes

- Move comment to correct constant (#629)
- Various cleanup (#635)
- Simplify `UninitSlice::as_uninit_slice_mut()` logic (#644)
- Use `self.` instead of `Self::` (#642)
- `BytesMut`: Assert alignment of `Shared` (#652)
- Remove unnecessary namespace qualifier (#660)
- Remove an unnecessary else branch (#662)
- Remove unreachable else branch (#661)
- make parameter mut in `From<Vec>` (#667)
- Restore commented tests (#665)
- Use `sub` instead of `offset` (#668)
- Calculate original capacity only if necessary (#666)
- `set_vec_pos` does not need a second parameter (#672)
- `get_vec_pos`: use `&self` instead of `&mut self` (#670)
- Refactor `split_at`/`split_to` (#663)
- Use `Iterator` from the prelude (#673)
- `copy_to_bytes`: Add panic section to docs (#676)
- Remove redundant reserve call (#674)
- Use `ManuallyDrop` instead of `mem::forget` (#675)


# 1.5.0 (September 7, 2023)

### Added
Expand Down
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ name = "bytes"
# When releasing to crates.io:
# - Update CHANGELOG.md.
# - Create "v1.x.y" git tag.
version = "1.5.0"
version = "1.7.1"
edition = "2018"
rust-version = "1.39"
license = "MIT"
authors = [
"Carl Lerche <[email protected]>",
Expand All @@ -15,7 +17,6 @@ repository = "https://github.com/tokio-rs/bytes"
readme = "README.md"
keywords = ["buffers", "zero-copy", "io"]
categories = ["network-programming", "data-structures"]
edition = "2018"

[features]
default = ["std"]
Expand All @@ -28,7 +29,7 @@ serde = { version = "1.0.60", optional = true, default-features = false, feature
serde_test = "1.0"

[target.'cfg(loom)'.dev-dependencies]
loom = "0.5"
loom = "0.7"

[package.metadata.docs.rs]
rustdoc-args = ["--cfg", "docsrs"]
9 changes: 9 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Security Policy

Bytes is part of the Tokio project and uses the same security policy as [Tokio][tokio-security].

## Report a security issue

The process for reporting an issue is the same as for [Tokio][tokio-security]. This includes private reporting via [email protected].

[tokio-security]: https://github.com/tokio-rs/tokio/security/policy
6 changes: 3 additions & 3 deletions benches/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn clone_static(b: &mut Bencher) {

b.iter(|| {
for _ in 0..1024 {
test::black_box(&bytes.clone());
test::black_box(test::black_box(&bytes).clone());
}
})
}
Expand All @@ -58,7 +58,7 @@ fn clone_shared(b: &mut Bencher) {

b.iter(|| {
for _ in 0..1024 {
test::black_box(&bytes.clone());
test::black_box(test::black_box(&bytes).clone());
}
})
}
Expand All @@ -70,7 +70,7 @@ fn clone_arc_vec(b: &mut Bencher) {

b.iter(|| {
for _ in 0..1024 {
test::black_box(&bytes.clone());
test::black_box(test::black_box(&bytes).clone());
}
})
}
Expand Down
6 changes: 0 additions & 6 deletions ci/test-stable.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@ set -ex

cmd="${1:-test}"

# Install cargo-hack for feature flag test
host=$(rustc -Vv | grep host | sed 's/host: //')
curl -LsSf https://github.com/taiki-e/cargo-hack/releases/latest/download/cargo-hack-$host.tar.gz | tar xzf - -C ~/.cargo/bin

# Run with each feature
# * --each-feature includes both default/no-default features
# * --optional-deps is needed for serde feature
cargo hack "${cmd}" --each-feature --optional-deps
# Run with all features
cargo "${cmd}" --all-features

cargo doc --no-deps --all-features

if [[ "${RUST_VERSION}" == "nightly"* ]]; then
# Check benchmarks
cargo check --benches
Expand Down
Empty file modified ci/tsan.sh
100644 → 100755
Empty file.
Loading