Commit Graph

120 Commits

Author SHA1 Message Date
Ivan Tham 71404633e8 Merge raw_vec into_box with previous impl<T, Global>
There are two separate `impl<T, Global>` which no special reason, it would be
better to merge both of them.
2020-05-31 17:19:06 +08:00
Ivan Tham 42a4f5ac50 Fix grammar in liballoc raw_vec 2020-05-29 00:40:41 +08:00
Nicholas Nethercote 9eb0399a9d Adjust the zero check in RawVec::grow.
This was supposed to land as part of #72227. (I wish `git push` would
abort when you have uncommited changes.)
2020-05-20 09:57:14 +10:00
Nicholas Nethercote f4b9dc31f6 Tiny Vecs are dumb.
Currently, if you repeatedly push to an empty vector, the capacity
growth sequence is 0, 1, 2, 4, 8, 16, etc. This commit changes the
relevant code (the "amortized" growth strategy) to skip 1 and 2 in most
cases, instead using 0, 4, 8, 16, etc. (You can still get a capacity of
1 or 2 using the "exact" growth strategy, e.g. via `reserve_exact()`.)

This idea (along with the phrase "tiny Vecs are dumb") comes from the
"doubling" growth strategy that was removed from `RawVec` in #72013.
That strategy was barely ever used -- only when a `VecDeque` was grown,
oddly enough -- which is why it was removed in #72013.

(Fun fact: until just a few days ago, I thought the "doubling" strategy
was used for repeated push case. In other words, this commit makes
`Vec`s behave the way I always thought they behaved.)

This change reduces the number of allocations done by rustc itself by
10% or more. It speeds up rustc, and will also speed up any other Rust
program that uses `Vec`s a lot.
2020-05-18 15:26:59 +10:00
Nicholas Nethercote 68b75033ad Split RawVec::grow up.
The amortized case is much more common than the exact case, and it is
typically instantiated many times.

Also, we can put a chunk of the code into a function that isn't generic
over T, which reduces the amount of LLVM IR generated quite a lot,
improving compile times.
2020-05-12 12:38:14 +10:00
Nicholas Nethercote f420726566 Remove RawVec::double.
It's only used once, for `VecDeque`, and can easily be replaced by
something else. The commit changes `grow_if_necessary` to `grow` to
avoid some small regressions caused by changed inlining.

The commit also removes `Strategy::Double`, and streamlines the
remaining variants of `Strategy`.

It's a compile time win on some benchmarks because the many
instantations of `RawVec::grow` are a little smaller.
2020-05-12 12:37:22 +10:00
Nicholas Nethercote a3cc435f57 Remove RawVec::double_in_place.
It's unused.
2020-05-12 08:39:08 +10:00
cohenarthur eda7f8fdff rename-unique: Rename Unique::empty() to Unique::dangling()
rename-unique: Change calls and doc in raw_vec.rs

rename-unique: Change empty() -> dangling() in const-ptr-unique-rpass.rs
2020-04-30 11:00:45 +02:00
Ralf Jung 7aebdb639a remove Unique::from for shared pointer types 2020-04-26 19:00:57 +02:00
Linus Färnstrand e4fc04b6df Use usize::MAX as assoc const in liballoc 2020-04-06 23:07:38 +02:00
Ralf Jung 6cbe1726a7 clarify safety in RawVec::into_box 2020-04-05 12:09:03 +02:00
Trevor Spiteri 2b718e8d9c use ManuallyDrop instead of forget inside collections
This commit changes some usage of mem::forget into mem::ManuallyDrop
in some Vec, VecDeque, BTreeMap and Box methods.

Before the commit, the generated IR for some of the methods was
longer, and even after optimization, some unwinding artifacts were
still present.
2020-04-04 14:30:33 +02:00
Tim Diekmann 89ed59d884 Add missing allocation guard in RawVec::grow 2020-04-01 10:26:30 +02:00
Tim Diekmann bf6a46db31 Make fields in MemoryBlock public 2020-03-28 20:22:07 +01:00
Tim Diekmann 03b055b0b4 Remove alignment from MemoryBlock 2020-03-26 17:14:12 +01:00
Tim Diekmann fed3d6e646 Fix safety section of RawVec::into_box 2020-03-26 17:13:47 +01:00
Tim Diekmann cbbdca0594 Fix wording in RawVec::from_raw_parts(_in) 2020-03-26 17:13:31 +01:00
Tim Diekmann b02e53f197 Remove check for ZST in RawVec::needs_to_grow 2020-03-26 17:13:25 +01:00
Tim Diekmann ad7de67a32 Refine docs for RawVec::from_raw_parts(_in) 2020-03-26 17:13:11 +01:00
Tim Diekmann aae3c52c7a Remove the note on the internal capacity field in RawVec 2020-03-26 17:12:57 +01:00
Tim Diekmann ba26a9e957 Fix assertion in shrink to use capacity() instead 2020-03-26 17:12:45 +01:00
Tim Diekmann 42a8547038 Fix comment in RawVec::into_box() 2020-03-26 17:12:35 +01:00
Tim Diekmann c1fa02331a Fix ZST handling for RawVec 2020-03-26 17:12:27 +01:00
Tim Diekmann 2526accdd3 Fix issues from review and unsoundness of RawVec::into_box 2020-03-26 17:11:47 +01:00
Tim Diekmann 56cbf2f22a Overhaul of the AllocRef trait to match allocator-wg's latest consens 2020-03-26 17:10:54 +01:00
Tim Diekmann f77afc8f9c Allow ZSTs in AllocRef 2020-03-08 11:01:12 +01:00
Tim Diekmann d8e3557dba Remove usable_size APIs 2020-03-03 00:08:24 +01:00
Tim Diekmann 25de80ad23 Remove common usage pattern from AllocRef 2020-02-10 18:38:09 +01:00
Tim Diekmann 7ca25db816 Rename Alloc to AllocRef 2020-01-27 21:39:51 +01:00
Mark Rousskov a06baa56b9 Format the world 2019-12-22 17:42:47 -05:00
Ross MacArthur f7256d28d1 Require issue = "none" over issue = "0" in unstable attributes 2019-12-21 13:16:18 +02:00
Mark Mansi 7d268119f0 no need to bootstrap 2019-12-18 20:19:05 -06:00
Mark Mansi 253543560a add fixme 2019-12-18 20:19:05 -06:00
Mark Mansi 951f041347 fix import 2019-12-18 20:19:05 -06:00
Mark Mansi baaf864e07 use usize::MAX instead of !0 2019-12-18 20:19:05 -06:00
Mark Mansi 3ec3fca414 remove a bit more hackery 2019-12-18 20:19:05 -06:00
Mark Mansi 17aa0cb2ca Remove a const-if-hack in RawVec 2019-12-18 20:19:05 -06:00
Mazdak Farrokhzad d5fe5831ec Const-stabilize Vec::new. 2019-09-16 16:45:16 +02:00
Alexander Regueiro 58a26c8fc0 Update src/liballoc/raw_vec.rs
Co-Authored-By: Mazdak Farrokhzad <twingoow@gmail.com>
2019-09-14 15:26:50 +01:00
Alexander Regueiro b0006dff10 A few cosmetic improvements to code & comments in liballoc and libcore 2019-09-06 16:02:25 +01:00
Simon Sapin 59a340963f Add the Layout of the failed allocation to TryReserveError::AllocError
… and add a separately-unstable field to force non-exhaustive matching
(`#[non_exhaustive]` is no implemented yet on enum variants)
so that we have the option to later expose the allocator’s error value.

CC https://github.com/rust-lang/wg-allocators/issues/23
2019-08-16 18:08:37 +02:00
Simon Sapin 36b18a1901 Rename CollectionAllocError to TryReserveError 2019-08-16 18:08:06 +02:00
Vadim Petrochenkov 3d0d6ee271 liballoc: Unconfigure tests during normal build
Remove additional libcore-like restrictions from liballoc, turns out the testing works ok if the tests are a part of liballoc itself.
2019-08-02 01:59:01 +03:00
bors 890881f8f4 Auto merge of #60340 - mgeier:cap-vs-capacity, r=alexcrichton
Rename .cap() methods to .capacity()

As mentioned in #60316, there are a few `.cap()` methods, which seem out-of-place because such methods are called `.capacity()` in the rest of the code.

This PR renames them to `.capacity()` but leaves `RawVec::cap()` in there for backwards compatibility.

I didn't try to mark the old version as "deprecated", because I guess this would cause too much noise.
2019-07-25 18:45:42 +00:00
Matthias Geier abe3bdf257 Remove RawVec::cap()
As suggested in https://github.com/rust-lang/rust/pull/60340#issuecomment-493681032
2019-06-25 15:44:21 +02:00
Aleksey Kladov a23a77fb19 avoid materializing unintialized Boxes in RawVec 2019-05-27 11:15:31 +03:00
Matthias Geier 0967d28be7 Rename .cap() methods to .capacity()
... but leave the old names in there for backwards compatibility.
2019-04-27 22:43:10 +02:00
Simon Sapin fc928a18ba Stabilize the alloc crate.
This implements RFC 2480:

* https://github.com/rust-lang/rfcs/pull/2480
* https://github.com/rust-lang/rfcs/blob/master/text/2480-liballoc.md

Closes https://github.com/rust-lang/rust/issues/27783
2019-04-12 20:07:30 +02:00
Alexander Regueiro 99ed06eb88 libs: doc comments 2019-02-10 23:57:25 +00:00
Mazdak Farrokhzad 2396780cda liballoc: revert nested imports style changes. 2019-02-03 08:27:44 +01:00