Commit Graph

307 Commits

Author SHA1 Message Date
Noah 230874f5a1 Fully inline BytesMut::new (#493) 2021-04-11 05:49:33 +09:00
Stepan Koltsov 8640174c94 Specialize copy_to_bytes for Chain and Take (#481)
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-04-11 03:56:35 +09:00
Dan Burkert a43f742c80 Add inline tags to UninitSlice methods (#443)
This appears to be the primary cause of significant performance
regressions in the `prost` test suite in the 0.5 to 0.6 transition.  See
danburkert/prost#381.
2021-04-11 03:19:30 +09:00
Stepan Koltsov 0688750f5f Panic on integer overflow in Chain::remaining (#482)
Make it safer.
2021-02-16 12:44:33 -08:00
Zettroke 62ba4a9c19 override put_slice for &mut [u8] (#483) 2021-02-15 16:35:01 -08:00
Alice Ryhl 1bcd09fecc Make bytes_mut -> chunk_mut rename more easily discoverable (#471) 2021-01-23 15:22:43 +09:00
Christopher Bunn 9b463abdd3 docs: fix broken Take link (#466) 2021-01-20 14:39:23 +09:00
Alice Ryhl 7c22cdf430 prepare 1.0.1 release (#460) 2021-01-11 18:07:46 +01:00
Ralf Jung caff82bb54 use Box::into_raw instead of mem-forget-in-disguise (#458) 2020-12-31 15:07:28 +01:00
laizy 4921a32c48 add inline for Vec::put_slice (#459) 2020-12-31 12:34:39 +01:00
Alice Ryhl ab9d9aa32c Fix deprecation warning (#457) 2020-12-29 22:46:39 +01:00
Carl Lerche d40a3d70c1 Rename Buf/BufMut, methods to chunk/chunk_mut (#450)
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-12-18 11:04:31 -08:00
Carl Lerche a1d54b1c27 remove unused Buf implementation. (#449)
The implementation of `Buf` for `Option<[u8; 1]>` was added to support
`IntoBuf`. The `IntoBuf` trait has since been removed.

Closes #444
2020-12-16 21:51:13 -08:00
Carl Lerche e52da8e1cb chore: prepare for v1.0.0 work (#448) 2020-12-12 08:25:14 -08:00
Carl Lerche d58e99485c Add Buf::copy_to_bytes(len) (#439)
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-20 11:00:35 -07:00
Carl Lerche 143861dec0 use checked addition with range (#438) 2020-10-20 10:26:38 -07:00
Carl Lerche 14b4e28a5f Switch BufMut::bytes_mut to&mut UninitSlice (#433)
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-19 15:48:23 -07:00
Matthias Einwag 79842672f4 De-emphasize Arc implementation in Bytes description (#436)
The previous description focussed a lot on the `Arc` based implementation
of `Bytes`. Given the vtable based implemetation, this is however not the
only valid implementation. This changes the description a bit in order
to de-emaphasize the `Arc` part, and to describe that other implementations
are possible.

This should also be necessary if the vtable gets public.
2020-10-19 12:32:20 -07:00
Carl Lerche 003543a312 remove new fns from combinator structs (#434)
This is not idiomatic.
2020-10-18 09:55:19 -07:00
Carl Lerche 16c888fbea Make BufMut an unsafe trait (#432)
Users of `BufMut` are unable to defend against incorrect implementations
of `BufMut`, this makes the trait unsafe to implement.

Fixes #329
2020-10-16 15:45:38 -07:00
Carl Lerche ad16e65c28 remove ext traits (#431) 2020-10-16 15:16:23 -07:00
Carl Lerche 69b7e70509 Remove BufMut::bytes_vectored_mut() (#430)
There are issues with regard to uninitialized memory. We are avoiding
stabilizing this function for now.
2020-10-16 11:56:03 -07:00
Carl Lerche 5133606f40 prepare for 0.6 work (#428) 2020-10-16 11:49:27 -07:00
Sean McArthur 8ec9733fc7 v0.5.6 2020-07-13 17:58:36 -07:00
Taiki Endo 63c9265f3c Change default lint level to warning and deny warnings in CI (#397) 2020-07-09 09:12:39 -07:00
Sean Leather 6ccbcdfbc0 docs: Clarify what BytesMut is (#375) 2020-07-09 09:11:45 -07:00
Bryan Donlan b83ea40780 BytesMut: Reuse buffer when data fully consumed via Buf
Closes #412
2020-07-08 15:28:36 -07:00
Juan Aguilar 2e16777240 Add inline attribute to BytesMut::as_mut (#410) 2020-07-05 17:43:26 -07:00
Juan Aguilar e81e1c3c4e Add inline attribute to BytesMut::set_len (#408) 2020-07-03 16:47:32 -07:00
Tomasz Miąsko 3d28557ac0 Remove unnecessary synchronization when cloning shared representation (#404) 2020-07-02 18:55:16 -07:00
Sean McArthur 7e158a1f92 v0.5.5 2020-06-18 14:30:11 -07:00
Mikhail Zabaluev c5fe74761d Remove outdated info on BytesMut::with_capacity (#394)
Remove a remark from the doc that pertained to the inline
layout and is no longer true.
2020-05-27 22:02:45 -07:00
Taiki Endo 7c29088aa4 Deny warnings for doc tests (#391) 2020-05-24 06:30:50 +09:00
Kirill Fomichev 0142960b4e Fix reference in Take docs (#383) 2020-05-22 14:33:06 +09:00
Taiki Endo 9a2e275ae3 Format with rustfmt (#389)
* Format with rustfmt

* Add rustfmt check to CI
2020-05-22 13:17:30 +09:00
Sean McArthur e186368e5b Update to loom v0.3 (#381) 2020-05-22 11:23:22 +09:00
Tim Hambourger f9e9196d20 Fix #354 -- Make advance_mut impl of BufMut for Vec<u8> panic if cnt > remaining 2020-03-25 12:30:15 -07:00
Tim Hambourger 90775ac26f Fix #352 -- Make freeze respect the start offset for BytesMuts in Vec mode 2020-03-24 11:14:16 -07:00
Sean McArthur 24b159c016 v0.5.4 2020-01-23 10:41:50 -08:00
Stepan Koltsov a4b63406c7 Do not panic on Bytes::slice_ref on empty slice (#355)
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-23 10:29:42 -08:00
南浦月 f812a9f70e merge hex & debug into fmt (#357) 2020-01-23 10:08:40 -08:00
Nikhil Benesch 5a5bb9ed2a Minor documentation fixes (#351)
* Remove incorrect comment about behavior of put_slice
* Improve grammar and clarity of BytesMut documentation
2020-01-23 10:06:49 -08:00
Andrew Tunnell-Jones 5369a989a4 Fix reversed arguments in PartialOrd impls (#358) 2020-01-23 10:06:00 -08:00
John-John Tedro 1efd9958a3 Assert that the alignment of Shared is appropriate (#362) 2020-01-23 10:05:20 -08:00
Stepan Koltsov ab3934634c rebuild_boxed_slice instead of rebuild_boxed_vec (#364)
"Promotable" `Bytes` object is constructed from disassembling a
boxed slice object, not a vec.

Thus we should reassemble data into a boxed slice, not into a vec.

Although, it does not create any problems in practice (`Box<[u8]>`
is allocated exactly the same way as `Vec<u8>`), technically it is
a violation of `Vec::from_raw_parts` spec which says that a pointer
"needs to have been previously allocated via `String`/`Vec<T>`".
2020-01-23 10:04:13 -08:00
Sean McArthur 952158eeb2 Fix Bytes::truncate losing the original Vec's capacity (#361) 2020-01-22 16:37:53 -08:00
Stepan Koltsov ec0825fe19 Make Bytes::new const fn (#356) 2020-01-09 14:27:28 -08:00
Sean McArthur 4efc6a7663 Improve assertion messages (#349) 2020-01-07 21:29:36 -08:00
Thayne McCombs 7974f2d645 Re-add impl From<BytesMut> for Bytes (#348) 2019-12-19 11:09:14 -08:00
Sean McArthur 419e36e67c Fix Bytes when Vec pointer's LSB is set (#346)
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-17 13:23:15 -08:00