Skip to content

Commit 3a1fd61

Browse files
committed
Auto merge of #48905 - Marwes:patch-1, r=<try>
Add missing inline annotations to Cell Were seeing some odd performance problems when using incremental compilation where `Rc` pointers were actually slower than `Arc` pointers (the problem goes away when using non-incremental compilation). I haven't been able to build rustc locally to verify that this fixes it but these missing inline annotations seem to be the only thing that could affect performance (to this extent). ``` test vector_push_back ... bench: 11,668,015 ns/iter (+/- 772,861) test vector_push_back_mut ... bench: 1,423,771 ns/iter (+/- 22,011) test vector_push_back_mut_rc ... bench: 1,181,765 ns/iter (+/- 123,724) test vector_push_back_rc ... bench: 17,141,746 ns/iter (+/- 203,048) ``` (Source and non incremental benchmarks orium/rpds#7 (comment))
2 parents 87344aa + 58fced4 commit 3a1fd61

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/libcore/cell.rs

+4
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ impl<T:Ord + Copy> Ord for Cell<T> {
331331

332332
#[stable(feature = "cell_from", since = "1.12.0")]
333333
impl<T> From<T> for Cell<T> {
334+
#[inline]
334335
fn from(t: T) -> Cell<T> {
335336
Cell::new(t)
336337
}
@@ -449,6 +450,7 @@ impl<T> Cell<T> {
449450
/// assert_eq!(cell.replace(10), 5);
450451
/// assert_eq!(cell.get(), 10);
451452
/// ```
453+
#[inline]
452454
#[stable(feature = "move_cell", since = "1.17.0")]
453455
pub fn replace(&self, val: T) -> T {
454456
mem::replace(unsafe { &mut *self.value.get() }, val)
@@ -466,6 +468,7 @@ impl<T> Cell<T> {
466468
///
467469
/// assert_eq!(five, 5);
468470
/// ```
471+
#[inline]
469472
#[stable(feature = "move_cell", since = "1.17.0")]
470473
pub fn into_inner(self) -> T {
471474
self.value.into_inner()
@@ -486,6 +489,7 @@ impl<T: Default> Cell<T> {
486489
/// assert_eq!(five, 5);
487490
/// assert_eq!(c.into_inner(), 0);
488491
/// ```
492+
#[inline]
489493
#[stable(feature = "move_cell", since = "1.17.0")]
490494
pub fn take(&self) -> T {
491495
self.replace(Default::default())

0 commit comments

Comments
 (0)