mirror of
https://github.com/openharmony/third_party_rust_rust-smallvec.git
synced 2026-07-21 01:55:25 -04:00
Auto merge of #113 - llogiq:simplify, r=mbrubeck
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 ``` <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-smallvec/113) <!-- Reviewable:end -->
This commit is contained in:
@@ -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]
|
||||
@@ -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) })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -602,15 +588,14 @@ 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();
|
||||
@@ -618,10 +603,11 @@ impl<A: Array> SmallVec<A> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user