Skip to content

Commit

Permalink
Some small simplifications
Browse files Browse the repository at this point in the history
benches show nothing out of the ordinary:

```
 name                               smallvecbench.txt ns/iter  smallvecbench-new.txt ns/iter  diff ns/iter   diff %  speedup
 bench_extend                       47                         47                                        0    0.00%   x 1.00
 bench_extend_from_slice            41                         41                                        0    0.00%   x 1.00
 bench_extend_from_slice_small      12                         12                                        0    0.00%   x 1.00
 bench_extend_from_slice_vec        55                         55                                        0    0.00%   x 1.00
 bench_extend_from_slice_vec_small  25                         25                                        0    0.00%   x 1.00
 bench_extend_small                 13                         13                                        0    0.00%   x 1.00
 bench_extend_vec                   66                         58                                       -8  -12.12%   x 1.14
 bench_extend_vec_small             24                         24                                        0    0.00%   x 1.00
 bench_from_slice                   80                         80                                        0    0.00%   x 1.00
 bench_from_slice_small             22                         23                                        1    4.55%   x 0.96
 bench_from_slice_vec               32                         30                                       -2   -6.25%   x 1.07
 bench_from_slice_vec_small         27                         27                                        0    0.00%   x 1.00
 bench_insert                       618                        605                                     -13   -2.10%   x 1.02
 bench_insert_from_slice            85                         85                                        0    0.00%   x 1.00
 bench_insert_many                  177                        177                                       0    0.00%   x 1.00
 bench_insert_small                 119                        120                                       1    0.84%   x 0.99
 bench_insert_vec                   541                        542                                       1    0.18%   x 1.00
 bench_insert_vec_small             123                        125                                       2    1.63%   x 0.98
 bench_macro_from_elem              35                         34                                       -1   -2.86%   x 1.03
 bench_macro_from_elem_small        7                          7                                         0    0.00%   x 1.00
 bench_macro_from_elem_vec          40                         34                                       -6  -15.00%   x 1.18
 bench_macro_from_elem_vec_small    27                         27                                        0    0.00%   x 1.00
 bench_macro_from_list              21                         22                                        1    4.76%   x 0.95
 bench_macro_from_list_vec          20                         21                                        1    5.00%   x 0.95
 bench_push                         388                        386                                      -2   -0.52%   x 1.01
 bench_push_small                   65                         66                                        1    1.54%   x 0.98
 bench_push_vec                     335                        338                                       3    0.90%   x 0.99
 bench_push_vec_small               44                         46                                        2    4.55%   x 0.96
 bench_pushpop                      746                        746                                       0    0.00%   x 1.00
 bench_pushpop_vec                  247                        247                                       0    0.00%   x 1.00
 bench_remove                       414                        411                                      -3   -0.72%   x 1.01
 bench_remove_small                 89                         90                                        1    1.12%   x 0.99
 bench_remove_vec                   424                        406                                     -18   -4.25%   x 1.04
 bench_remove_vec_small             80                         81                                        1    1.25%   x 0.99
```
  • Loading branch information
llogiq committed Aug 7, 2018
1 parent 62c525a commit 4d02e41
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,7 @@ impl<'a, T: 'a> Iterator for Drain<'a,T> {

#[inline]
fn next(&mut self) -> Option<T> {
match self.iter.next() {
None => None,
Some(reference) => {
unsafe {
Some(ptr::read(reference))
}
}
}
self.iter.next().map(|reference| unsafe { ptr::read(reference) })
}

#[inline]
Expand All @@ -259,14 +252,7 @@ impl<'a, T: 'a> Iterator for Drain<'a,T> {
impl<'a, T: 'a> DoubleEndedIterator for Drain<'a, T> {
#[inline]
fn next_back(&mut self) -> Option<T> {
match self.iter.next_back() {
None => None,
Some(reference) => {
unsafe {
Some(ptr::read(reference))
}
}
}
self.iter.next_back().map(|reference| unsafe { ptr::read(reference) })
}
}

Expand Down Expand Up @@ -602,26 +588,26 @@ impl<A: Array> SmallVec<A> {
pub fn grow(&mut self, new_cap: usize) {
unsafe {
let (ptr, &mut len, cap) = self.triple_mut();
let spilled = self.spilled();
let unspilled = !self.spilled();
assert!(new_cap >= len);
if new_cap <= self.inline_size() {
if !spilled {
if unspilled {
return;
}
self.data = SmallVecData::from_inline(mem::uninitialized());
ptr::copy_nonoverlapping(ptr, self.data.inline_mut().ptr_mut(), len);
deallocate(ptr, cap);
} else if new_cap != cap {
let mut vec = Vec::with_capacity(new_cap);
let new_alloc = vec.as_mut_ptr();
mem::forget(vec);
ptr::copy_nonoverlapping(ptr, new_alloc, len);
self.data = SmallVecData::from_heap(new_alloc, len);
self.capacity = new_cap;
if spilled {
deallocate(ptr, cap);
if unspilled {
return;
}
}
deallocate(ptr, cap);
}
}

Expand Down

1 comment on commit 4d02e41

@Shnatsel
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be the commit that introduced #148

Please sign in to comment.