Skip to content

Commit 4d02e41

Browse files
committed
Some small simplifications
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 ```
1 parent 62c525a commit 4d02e41

File tree

1 file changed

+7
-21
lines changed

1 file changed

+7
-21
lines changed

lib.rs

+7-21
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,7 @@ impl<'a, T: 'a> Iterator for Drain<'a,T> {
240240

241241
#[inline]
242242
fn next(&mut self) -> Option<T> {
243-
match self.iter.next() {
244-
None => None,
245-
Some(reference) => {
246-
unsafe {
247-
Some(ptr::read(reference))
248-
}
249-
}
250-
}
243+
self.iter.next().map(|reference| unsafe { ptr::read(reference) })
251244
}
252245

253246
#[inline]
@@ -259,14 +252,7 @@ impl<'a, T: 'a> Iterator for Drain<'a,T> {
259252
impl<'a, T: 'a> DoubleEndedIterator for Drain<'a, T> {
260253
#[inline]
261254
fn next_back(&mut self) -> Option<T> {
262-
match self.iter.next_back() {
263-
None => None,
264-
Some(reference) => {
265-
unsafe {
266-
Some(ptr::read(reference))
267-
}
268-
}
269-
}
255+
self.iter.next_back().map(|reference| unsafe { ptr::read(reference) })
270256
}
271257
}
272258

@@ -602,26 +588,26 @@ impl<A: Array> SmallVec<A> {
602588
pub fn grow(&mut self, new_cap: usize) {
603589
unsafe {
604590
let (ptr, &mut len, cap) = self.triple_mut();
605-
let spilled = self.spilled();
591+
let unspilled = !self.spilled();
606592
assert!(new_cap >= len);
607593
if new_cap <= self.inline_size() {
608-
if !spilled {
594+
if unspilled {
609595
return;
610596
}
611597
self.data = SmallVecData::from_inline(mem::uninitialized());
612598
ptr::copy_nonoverlapping(ptr, self.data.inline_mut().ptr_mut(), len);
613-
deallocate(ptr, cap);
614599
} else if new_cap != cap {
615600
let mut vec = Vec::with_capacity(new_cap);
616601
let new_alloc = vec.as_mut_ptr();
617602
mem::forget(vec);
618603
ptr::copy_nonoverlapping(ptr, new_alloc, len);
619604
self.data = SmallVecData::from_heap(new_alloc, len);
620605
self.capacity = new_cap;
621-
if spilled {
622-
deallocate(ptr, cap);
606+
if unspilled {
607+
return;
623608
}
624609
}
610+
deallocate(ptr, cap);
625611
}
626612
}
627613

0 commit comments

Comments
 (0)