aboutsummaryrefslogtreecommitdiff
path: root/tests (follow)
AgeCommit message (Collapse)AuthorFilesLines
2023-10-02Various cleanup (#635)Gravatar Alice Ryhl 1-1/+1
2023-06-05Fix CI failure (#616)Gravatar Taiki Endo 2-0/+2
2023-02-10Implement BufMut for `&mut [MaybeUninit<u8>]` (#597)Gravatar Michal Nazarewicz 1-13/+110
2023-01-31Avoid large reallocations when freezing BytesMut (#592)Gravatar brian m. carlson 1-0/+45
When we freeze a BytesMut, we turn it into a Vec, and then convert that to a Bytes. Currently, this happen using Vec::into_boxed_slice, which reallocates to a slice of the same length as the Vev if the length and the capacity are not equal. This can pose a performance problem if the Vec is large or if this happens many times in a loop. Instead, let's compare the length and capacity, and if they're the same, continue to handle this using into_boxed_slice. Otherwise, since we have a type of vtable which can handle a separate capacity, the shared vtable, let's turn our Vec into that kind of Bytes. While this does not avoid allocation altogether, it performs a fixed size allocation and avoids any need to memcpy.
2022-07-30Fix reserve over allocating underlying buffer (#560)Gravatar Matt Schulte 1-0/+28
Fixes calls to `reserve` when the underlying shared buffer was already big enough to fit the requested capacity. Previously a new even larger buffer was created anyways. This could eventually lead to an OOM condition.
2022-07-13Add conversion from Bytes to Vec<u8> (#547)Gravatar Jiahao XU 3-0/+128
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> Co-authored-by: Alice Ryhl <aliceryhl@google.com>
2022-07-10Add conversion from BytesMut to Vec<u8> (#543)Gravatar Jiahao XU 1-0/+37
2022-07-09miri: don't use int2ptr casts for invalid pointers (#553)Gravatar Alice Ryhl 1-1/+10
2022-06-23chore: Fix unused warnings (#551)Gravatar Lucio Franco 1-2/+2
2022-06-11Fix chain remaining_mut(), allowing to chain growing buffer (#488)Gravatar Zettroke 1-0/+22
2022-04-28Fix bugs in `BytesMut::reserve_inner` (#544)Gravatar Jiahao XU 1-0/+19
2022-03-16Optimize BytesMut::reserve: Reuse vec if possible (#529)Gravatar Jiahao XU 1-1/+1
* Optimize `BytesMut::reserve`: Reuse vec if possible If the `BytesMut` holds a unqiue reference to `KIND_ARC` while the capacity of the `Vec` is not big enough , reuse the existing `Vec` instead of allocating a new one. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2022-01-24Implement `Extend<Bytes>` for `BytesMut` (#527)Gravatar Rob Ede 1-0/+7
2022-01-24Address various clippy warnings (#528)Gravatar Rob Ede 2-6/+5
2021-11-07Appease miri (#515)Gravatar Noah Kennedy 1-39/+65
Rewrote the ledger in test_bytes_vec_alloc.rs to not piss off miri. The ledger is now a table within the allocator, which seems to satisfy miri. The old solution was to bundle an extra usize into the beginning of each allocation and then index past the start when deallocating data to get the size.
2021-08-24impl From<Box<[u8]>> for Bytes (#504)Gravatar Ian Jackson 1-0/+8
2021-08-09BufMut::put_bytes(self, val, cnt) (#487)Gravatar Stepan Koltsov 2-0/+26
Equivalent to ``` for _ in 0..cnt { self.put_u8(val); } ``` but may work faster. Name and signature is chosen to be consistent with `ptr::write_bytes`. Include three specializations: * `Vec<u8>` * `&mut [u8]` * `BytesMut` `BytesMut` and `&mut [u8]` specializations use `ptr::write`, `Vec<u8>` specialization uses `Vec::resize`.
2021-08-09Clarify BufPut::put_int behavior (#486)Gravatar Stepan Koltsov 1-0/+28
* writes low bytes, discards high bytes * panics if `nbytes` is greater than 8
2021-08-07Clarify BufMut allocation guarantees (#501)Gravatar Alice Ryhl 1-2/+2
2021-07-05Keep capacity when unsplit on empty other buf (#502)Gravatar Gbillou 1-0/+25
2021-04-11Specialize copy_to_bytes for Chain and Take (#481)Gravatar Stepan Koltsov 2-0/+41
Avoid allocation when `Take` or `Chain` is composed of `Bytes` objects. This works now for `Take`. `Chain` it works if the requested bytes does not cross boundary between `Chain` members.
2021-02-15override put_slice for &mut [u8] (#483)Gravatar Zettroke 1-0/+3
2020-12-29CI: run test suite in Miri (#456)Gravatar Ralf Jung 2-3/+6
2020-12-18Rename Buf/BufMut, methods to chunk/chunk_mut (#450)Gravatar Carl Lerche 5-21/+21
The `bytes()` / `bytes_mut()` name implies the method returns the full set of bytes represented by `Buf`/`BufMut`. To rectify this, the methods are renamed to `chunk()` and `chunk_mut()` to reflect the partial nature of the returned byte slice. `bytes_vectored()` is renamed `chunks_vectored()`. Closes #447
2020-10-20Add `Buf::copy_to_bytes(len)` (#439)Gravatar Carl Lerche 2-1/+18
This method replaces `Buf::to_bytes()`, providing a method that copies a subset of the remaining buffer into a `Bytes` value. As this is strictly more flexible, `to_bytes()` is removed. Fixes: #129, #398
2020-10-19Switch `BufMut::bytes_mut` to`&mut UninitSlice` (#433)Gravatar Carl Lerche 2-3/+31
The way BufMut uses MaybeUninit can lead to unsoundness. This replaces MaybeUnit with a type owned by bytes so we can ensure the usage patterns are sound. Refs: #328
2020-10-16Make BufMut an unsafe trait (#432)Gravatar Carl Lerche 1-1/+1
Users of `BufMut` are unable to defend against incorrect implementations of `BufMut`, this makes the trait unsafe to implement. Fixes #329
2020-10-16remove ext traits (#431)Gravatar Carl Lerche 3-5/+4
2020-10-16Remove BufMut::bytes_vectored_mut() (#430)Gravatar Carl Lerche 1-19/+0
There are issues with regard to uninitialized memory. We are avoiding stabilizing this function for now.
2020-07-09Change default lint level to warning and deny warnings in CI (#397)Gravatar Taiki Endo 9-9/+9
2020-07-08BytesMut: Reuse buffer when data fully consumed via BufGravatar Bryan Donlan 1-0/+16
Closes #412
2020-05-22Format with rustfmt (#389)Gravatar Taiki Endo 7-14/+15
* Format with rustfmt * Add rustfmt check to CI
2020-05-22Fix tests for no_std build (#384)Gravatar Cheng XU 4-3/+11
This fixes `cargo test --no-default-features`.
2020-03-25Fix #354 -- Make advance_mut impl of BufMut for Vec<u8> panic if cnt > remainingGravatar Tim Hambourger 1-3/+2
2020-03-24Fix #352 -- Make freeze respect the start offset for BytesMuts in Vec modeGravatar Tim Hambourger 1-0/+66
2020-01-23Do not panic on Bytes::slice_ref on empty slice (#355)Gravatar Stepan Koltsov 1-15/+14
Use case: ``` let bytes: Bytes = ... let subbytes = bytes.slice(a..b); // where a == b let slice = &subbytes[..]; let slice_bytes = bytes.slice_ref(slice); ``` Last line should not panic, because `slice` object is derived from the original `Bytes` object. Before this commit it panics, because `Bytes::slice` returns a fresh `Bytes` object when `begin == end`.
2020-01-22Fix Bytes::truncate losing the original Vec's capacity (#361)Gravatar Sean McArthur 2-1/+76
2019-12-17Fix Bytes when Vec pointer's LSB is set (#346)Gravatar Sean McArthur 1-0/+67
This separates the `SharedVtable` into 3: - `PromotableEvenVtable`: The original `SharedVtable`, which will promote the `Vec` to `Shared` on the first clone, and is selected when the `Vec`'s pointer has the LSB unset. - `PromotableOddVtable`: Similar to the `PromotableEvenVtable`, but selected when the `Vec`'s pointer has the LSB set. This vtable differs in the masking used when reconstructing the `Vec`. - `SharedVtable`: This no longer checks if its current kind is `VEC` or `ARC`, and is only created by the "promotable" vtables. This also adds a test using an "odd" global allocator that purposefully bumps all pointers with alignment of 1. Closes #343
2019-12-12Assert the LSB is 0 when converting Vec into BytesGravatar Sean McArthur 1-2/+18
2019-12-10Make Deref impls of Buf and BufMut forward more methodsGravatar Sean McArthur 2-0/+59
2019-12-04Add must_use to split, split_off, and split_toGravatar Sean McArthur 1-11/+11
2019-12-01Fix regression in Bytes::truncate (#333)Gravatar Mikhail Zabaluev 1-0/+12
When the length to truncate is greater than the buffer's current length, do nothing instead of clearing the contents.
2019-11-20implicitly grow BytesMut; add BufMutExt::chain_mut (#316)Gravatar Carl Lerche 3-11/+41
This brings `BytesMut` in line with `Vec<u8>` behavior. This also fixes an existing bug in BytesMut::bytes_mut that exposes invalid slices. The bug was recently introduced and was only on master and never released to `crates.io`. In order to fix a test, `BufMutExt::chain_mut` is provided. Withou this, it is not possible to chain two `&mut [u8]`. Closes #170
2019-11-13Change loom tests to use cfg(loom) internally (#314)Gravatar Sean McArthur 1-73/+0
2019-10-31Move "extra" methods to extension traits (#306)Gravatar Sean McArthur 3-6/+6
2019-10-24Change BufMut methods that expose maybe-uninitialized bytes (#305)Gravatar Sean McArthur 2-12/+15
- The return type of `BufMut::bytes_mut` is now `&mut [MaybeUninit<u8>]`. - The argument type of `BufMut::bytes_vectored_mut` is now `&mut [bytes::buf::IoSliceMut]`. - `bytes::buf::IoSliceMut` is a `repr(transparent)` wrapper around an `std::io::IoSliceMut`, but does not expose the inner bytes with a safe API, since they might be uninitialized. - `BufMut::bytesMut` and `BufMut::bytes_vectored_mut` are no longer `unsafe fn`, since the types encapsulate the unsafety instead.
2019-10-16Remove Buf impl for &str (#301)Gravatar Sean McArthur 1-1/+1
A `&str` cannot arbitrarily advance bytes, since it will panic if advanced to the middle of a Unicode segment.
2019-10-16Refactor Bytes to use an internal vtable (#298)Gravatar Sean McArthur 4-163/+177
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.)
2019-08-27Make From only for static slices to BytesGravatar Douman 1-2/+2
2019-08-27Remove IntoBuf/FromBuf (#288)Gravatar Douman 4-43/+10
As consequence Buf::collect is removed as well, which is replaced with `Buf::into_bytes`. The advantage of `Buf::into_bytes` is that it can be optimized in cases where converting a `T: Buf` into a `Bytes` instance is efficient.