From e235988ef28f48d43a415764546864c75eec684e Mon Sep 17 00:00:00 2001 From: sundyli <543950155@qq.com> Date: Tue, 18 Jan 2022 09:03:45 +0800 Subject: [PATCH] Add extend_from_iter into growable trait --- benches/growable.rs | 10 ++++++++++ src/array/growable/mod.rs | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/benches/growable.rs b/benches/growable.rs index ca7ac8a9045..ea6d2ed9a51 100644 --- a/benches/growable.rs +++ b/benches/growable.rs @@ -19,6 +19,16 @@ fn add_benchmark(c: &mut Criterion) { }) }); + c.bench_function("growable::dyn_primitive::non_null::non_null", |b| { + b.iter(|| { + let mut a: Box = + Box::new(GrowablePrimitive::new(vec![&i32_array], false, 1026 * 10)); + + let iter = values.clone().into_iter().map(|start| (0, start, 10)); + a.extend_from_iter(Box::new(iter)); + }) + }); + let i32_array = create_primitive_array::(1026 * 10, 0.0); c.bench_function("growable::primitive::non_null::null", |b| { b.iter(|| { diff --git a/src/array/growable/mod.rs b/src/array/growable/mod.rs index c6d45356237..ef190ec3ca3 100644 --- a/src/array/growable/mod.rs +++ b/src/array/growable/mod.rs @@ -40,6 +40,13 @@ pub trait Growable<'a> { /// Extends this [`Growable`] with null elements, disregarding the bound arrays fn extend_validity(&mut self, additional: usize); + /// Extends this [`Growable`] by iterator. + fn extend_from_iter(&mut self, iter: Box>) { + for (index, start, len) in iter { + self.extend(index, start, len); + } + } + /// Converts this [`Growable`] to an [`Arc`], thereby finishing the mutation. /// Self will be empty after such operation. fn as_arc(&mut self) -> std::sync::Arc {