Skip to content

Commit

Permalink
Auto merge of #48905 - Marwes:patch-1, r=<try>
Browse files Browse the repository at this point in the history
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))
  • Loading branch information
bors committed Mar 10, 2018
2 parents 87344aa + 58fced4 commit 3a1fd61
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/libcore/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ impl<T:Ord + Copy> Ord for Cell<T> {

#[stable(feature = "cell_from", since = "1.12.0")]
impl<T> From<T> for Cell<T> {
#[inline]
fn from(t: T) -> Cell<T> {
Cell::new(t)
}
Expand Down Expand Up @@ -449,6 +450,7 @@ impl<T> Cell<T> {
/// assert_eq!(cell.replace(10), 5);
/// assert_eq!(cell.get(), 10);
/// ```
#[inline]
#[stable(feature = "move_cell", since = "1.17.0")]
pub fn replace(&self, val: T) -> T {
mem::replace(unsafe { &mut *self.value.get() }, val)
Expand All @@ -466,6 +468,7 @@ impl<T> Cell<T> {
///
/// assert_eq!(five, 5);
/// ```
#[inline]
#[stable(feature = "move_cell", since = "1.17.0")]
pub fn into_inner(self) -> T {
self.value.into_inner()
Expand All @@ -486,6 +489,7 @@ impl<T: Default> Cell<T> {
/// assert_eq!(five, 5);
/// assert_eq!(c.into_inner(), 0);
/// ```
#[inline]
#[stable(feature = "move_cell", since = "1.17.0")]
pub fn take(&self) -> T {
self.replace(Default::default())
Expand Down

0 comments on commit 3a1fd61

Please sign in to comment.