From e45975f65a269e040bd813adc0c604311707c791 Mon Sep 17 00:00:00 2001 From: haixuanTao Date: Fri, 3 Nov 2023 16:30:01 +0100 Subject: [PATCH] Use cleaner `__from_elem` `avec` constructor --- apis/python/operator/src/lib.rs | 7 ++----- apis/rust/node/src/node/mod.rs | 6 ++---- binaries/runtime/src/operator/python.rs | 6 ++---- binaries/runtime/src/operator/shared_lib.rs | 5 +---- 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/apis/python/operator/src/lib.rs b/apis/python/operator/src/lib.rs index 26a13ca0..83745b9c 100644 --- a/apis/python/operator/src/lib.rs +++ b/apis/python/operator/src/lib.rs @@ -151,7 +151,7 @@ pub fn metadata_to_pydict<'a>(metadata: &'a Metadata, py: Python<'a>) -> &'a PyD mod tests { use std::sync::Arc; - use aligned_vec::{avec, AVec, ConstAlign}; + use aligned_vec::{AVec, ConstAlign}; use arrow::{ array::{ ArrayData, ArrayRef, BooleanArray, Float64Array, Int32Array, Int64Array, Int8Array, @@ -169,10 +169,7 @@ mod tests { fn assert_roundtrip(arrow_array: &ArrayData) -> Result<()> { let size = required_data_size(arrow_array); - let mut sample: AVec> = AVec::new(128); - for _ in 0..size { - sample.push(0); - } + let mut sample: AVec> = AVec::__from_elem(128, 0, size); let info = copy_array_into_sample(&mut sample, arrow_array)?; diff --git a/apis/rust/node/src/node/mod.rs b/apis/rust/node/src/node/mod.rs index e917a8ee..31725c89 100644 --- a/apis/rust/node/src/node/mod.rs +++ b/apis/rust/node/src/node/mod.rs @@ -257,10 +257,8 @@ impl DoraNode { len: data_len, } } else { - let mut avec: AVec> = AVec::new(128); - for _ in 0..data_len { - avec.push(0); - } + let avec: AVec> = AVec::__from_elem(128, 0, data_len); + avec.into() }; diff --git a/binaries/runtime/src/operator/python.rs b/binaries/runtime/src/operator/python.rs index 97762783..491536fa 100644 --- a/binaries/runtime/src/operator/python.rs +++ b/binaries/runtime/src/operator/python.rs @@ -312,10 +312,8 @@ mod callback_impl { .wrap_err("failed to request output sample")? .wrap_err("failed to allocate output sample") } else { - let mut avec: AVec> = AVec::new(128); - for _ in 0..data_len { - avec.push(0); - } + let avec: AVec> = AVec::__from_elem(128, 0, data_len); + Ok(avec.into()) } }; diff --git a/binaries/runtime/src/operator/shared_lib.rs b/binaries/runtime/src/operator/shared_lib.rs index 65f6b098..ca758c4f 100644 --- a/binaries/runtime/src/operator/shared_lib.rs +++ b/binaries/runtime/src/operator/shared_lib.rs @@ -134,10 +134,7 @@ impl<'lib> SharedLibraryOperator<'lib> { }; let total_len = required_data_size(&arrow_array); - let mut sample: AVec> = AVec::new(128); - for _ in 0..total_len { - sample.push(0); - } + let mut sample: AVec> = AVec::__from_elem(128, 0, total_len); let type_info = match copy_array_into_sample(&mut sample, &arrow_array) { Ok(t) => t,