This is an automated email from the ASF dual-hosted git repository.

tustvold pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/master by this push:
     new 97b4f6551 Derive Copy,Clone for BasicDecimal (#2495)
97b4f6551 is described below

commit 97b4f65518a358724b549790f53ec284eee63e50
Author: Raphael Taylor-Davies <[email protected]>
AuthorDate: Thu Aug 18 13:59:22 2022 +0100

    Derive Copy,Clone for BasicDecimal (#2495)
    
    * Derive Copy,Clone for BasicDecimal
    
    * Clippy
---
 arrow/benches/array_from_vec.rs | 28 +++++++++++++++-------------
 arrow/src/util/decimal.rs       |  4 ++--
 2 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/arrow/benches/array_from_vec.rs b/arrow/benches/array_from_vec.rs
index ab39a3fb8..59bef65a1 100644
--- a/arrow/benches/array_from_vec.rs
+++ b/arrow/benches/array_from_vec.rs
@@ -87,20 +87,11 @@ fn decimal128_array_from_vec(array: &[Option<i128>]) {
     );
 }
 
-fn decimal256_array_from_vec() {
-    // bench decimal256array
-    // create option<into<decimal256>> array
-    let size = 1 << 10;
-    let mut array = vec![];
-    let mut rng = rand::thread_rng();
-    for _ in 0..size {
-        let decimal =
-            Decimal256::from(BigInt::from(rng.gen_range::<i128, 
_>(0..9999999999999)));
-        array.push(Some(decimal));
-    }
+fn decimal256_array_from_vec(array: &[Option<Decimal256>]) {
     criterion::black_box(
         array
-            .into_iter()
+            .iter()
+            .copied()
             .collect::<Decimal256Array>()
             .with_precision_and_scale(70, 2)
             .unwrap(),
@@ -120,9 +111,20 @@ fn decimal_benchmark(c: &mut Criterion) {
         b.iter(|| decimal128_array_from_vec(array.as_slice()))
     });
 
+    // bench decimal256array
+    // create option<into<decimal256>> array
+    let size = 1 << 10;
+    let mut array = vec![];
+    let mut rng = rand::thread_rng();
+    for _ in 0..size {
+        let decimal =
+            Decimal256::from(BigInt::from(rng.gen_range::<i128, 
_>(0..9999999999999)));
+        array.push(Some(decimal));
+    }
+
     // bench decimal256 array
     c.bench_function("decimal256_array_from_vec 32768", |b| {
-        b.iter(|| decimal256_array_from_vec)
+        b.iter(|| decimal256_array_from_vec(array.as_slice()))
     });
 }
 
diff --git a/arrow/src/util/decimal.rs b/arrow/src/util/decimal.rs
index 043e37ddb..2e5cddc87 100644
--- a/arrow/src/util/decimal.rs
+++ b/arrow/src/util/decimal.rs
@@ -26,7 +26,7 @@ use num::bigint::BigInt;
 use num::Signed;
 use std::cmp::{min, Ordering};
 
-#[derive(Debug)]
+#[derive(Debug, Clone, Copy)]
 pub struct BasicDecimal<const BYTE_WIDTH: usize> {
     precision: usize,
     scale: usize,
@@ -247,7 +247,7 @@ impl Decimal256 {
     }
 
     /// Constructs a `BigInt` from this `Decimal256` value.
-    pub(crate) fn to_big_int(&self) -> BigInt {
+    pub(crate) fn to_big_int(self) -> BigInt {
         BigInt::from_signed_bytes_le(&self.value)
     }
 }

Reply via email to