Skip to content

Commit

Permalink
Rollup merge of #122099 - Urgau:btreemap-inline-new, r=Amanieu
Browse files Browse the repository at this point in the history
Add  `#[inline]` to `BTreeMap::new` constructor

This PR add the `#[inline]` attribute to `BTreeMap::new` constructor as to make it eligible for inlining.

<details>

For some context: I was profiling `rustc --check-cfg` with callgrind and due to the way we currently setup all the targets and we end-up calling `BTreeMap::new` multiple times for (nearly) all the targets. Adding the `#[inline]` attribute reduced the number of instructions needed.

</details>
  • Loading branch information
matthiaskrgr authored Mar 8, 2024
2 parents f586a79 + cc38c1e commit d16c55d
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions library/alloc/src/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ impl<K, V> BTreeMap<K, V> {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_btree_new", since = "1.66.0")]
#[inline]
#[must_use]
pub const fn new() -> BTreeMap<K, V> {
BTreeMap { root: None, length: 0, alloc: ManuallyDrop::new(Global), _marker: PhantomData }
Expand Down

0 comments on commit d16c55d

Please sign in to comment.