rust/library/alloc/src
bors 43a71dc732 Auto merge of #96002 - nnethercote:speed-up-Vec-clear-2, r=m-ou-se
Speed up Vec::clear().

Currently it just calls `truncate(0)`. `truncate()` is (a) not marked as
`#[inline]`, and (b) more general than needed for `clear()`.

This commit changes `clear()` to do the work itself. This modest change
was first proposed in rust-lang#74172, where the reviewer rejected it because
there was insufficient evidence that `Vec::clear()`'s performance
mattered enough to justify the change. Recent changes within rustc have
made `Vec::clear()` hot within `macro_parser.rs`, so the change is now
clearly worthwhile.

Although it doesn't show wins on CI perf runs, this seems to be because they
use PGO. But not all platforms currently use PGO. Also, local builds don't use
PGO, and `truncate` sometimes shows up in an over-represented fashion in local
profiles. So local profiling will be made easier by this change.

Note that this will also benefit `String::clear()`, because it just
calls `Vec::clear()`.

Finally, the commit removes the `vec-clear.rs` codegen test. It was
added in #52908. From before then until now, `Vec::clear()` just called
`Vec::truncate()` with a zero length. The body of Vec::truncate() has
changed a lot since then. Now that `Vec::clear()` is doing actual work
itself, and not just calling `Vec::truncate()`, it's not surprising that
its generated code includes a load and an icmp. I think it's reasonable
to remove this test.

r? `@m-ou-se`
2022-04-17 03:08:45 +00:00
..
alloc Rename AllocRef to Allocator and (de)alloc to (de)allocate 2020-12-04 14:47:15 +01:00
boxed Add ThinBox type for 1 stack pointer sized heap allocated trait objects 2022-04-08 09:00:16 -07:00
collections Rollup merge of #96070 - Gumichocopengin8:test/btree-map, r=thomcc 2022-04-16 07:12:48 +02:00
ffi Fix targets not supporting target_has_atomic = "ptr" 2022-04-14 21:53:11 +03:00
raw_vec Add a unit test for zero-sized types in RawVec. 2021-11-26 19:30:45 +11:00
rc Use implicit capture syntax in format_args 2022-03-10 10:23:40 -05:00
sync Use implicit capture syntax in format_args 2022-03-10 10:23:40 -05:00
vec Speed up Vec::clear(). 2022-04-13 15:39:35 +10:00
alloc.rs trivial cfg(bootstrap) changes 2022-04-05 23:18:40 +02:00
borrow.rs trivial cfg(bootstrap) changes 2022-04-05 23:18:40 +02:00
boxed.rs impl const Default for Box<[T]> and Box<str> 2022-04-11 12:14:18 -07:00
fmt.rs Use implicit capture syntax in format_args 2022-03-10 10:23:40 -05:00
lib.rs library: Use type aliases to make CStr(ing) in libcore/liballoc unstable 2022-04-14 21:53:11 +03:00
macros.rs Add diagnostic items for macros 2022-01-06 14:59:33 +00:00
raw_vec.rs formatting 2022-04-06 01:36:46 +05:30
rc.rs Auto merge of #95224 - mjbshaw:patch-1, r=yaahc 2022-04-15 23:15:51 +00:00
slice.rs library: Move CStr to libcore, and CString to liballoc 2022-04-14 21:53:11 +03:00
str.rs trivial cfg(bootstrap) changes 2022-04-05 23:18:40 +02:00
string.rs Rework String UTF-8 Documentation 2022-04-09 09:27:32 -04:00
sync.rs hide an #[allow] directive from the Arc::new_cyclic doc example 2022-04-07 18:00:46 -07:00
task.rs Document From implementations for Waker and RawWaker 2021-04-22 14:16:33 -07:00
tests.rs Use implicit capture syntax in format_args 2022-03-10 10:23:40 -05:00