Skip to content

Commit 1b929ff

Browse files
Liyixin95liyixin
authored andcommitted
perf: Remove redundant clone (pola-rs#23771)
Co-authored-by: liyixin <[email protected]>
1 parent fe692ff commit 1b929ff

File tree

84 files changed

+130
-198
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+130
-198
lines changed

crates/polars-arrow/src/ffi/schema.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl ArrowSchema {
9494

9595
let metadata = if let ArrowDataType::Extension(ext) = field.dtype() {
9696
// append extension information.
97-
let mut metadata = metadata.clone();
97+
let mut metadata = metadata;
9898

9999
// metadata
100100
if let Some(extension_metadata) = &ext.metadata {

crates/polars-arrow/src/io/ipc/read/flight.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ impl FlightConsumer {
348348
mmap_record(
349349
&self.md.schema,
350350
&self.md.ipc_schema.fields,
351-
arrow_data.clone(),
351+
arrow_data,
352352
batch,
353353
0,
354354
&self.dictionaries,

crates/polars-compute/src/propagate_dictionary.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub fn propagate_dictionary_value_nulls(
7373
// Filter out the null values
7474
let values = crate::filter::filter_with_bitmap(&values, values_validity);
7575
let values = values.as_any().downcast_ref::<BinaryViewArray>().unwrap();
76-
let values = unsafe { values.to_utf8view_unchecked() }.clone();
76+
let values = unsafe { values.to_utf8view_unchecked() };
7777

7878
// Explicitly set the values validity to none.
7979
assert_eq!(values.null_count(), 0);

crates/polars-core/src/chunked_array/builder/list/anonymous.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl<'a> AnonymousListBuilder<'a> {
9999
if slf.fast_explode {
100100
ca.set_fast_explode();
101101
}
102-
ca.field = Arc::new(Field::new(slf.name.clone(), list_dtype_logical));
102+
ca.field = Arc::new(Field::new(slf.name, list_dtype_logical));
103103
ca
104104
}
105105
}
@@ -165,7 +165,7 @@ impl ListBuilderTrait for AnonymousOwnedListBuilder {
165165
if slf.fast_explode {
166166
ca.set_fast_explode();
167167
}
168-
ca.field = Arc::new(Field::new(slf.name.clone(), list_dtype_logical));
168+
ca.field = Arc::new(Field::new(slf.name, list_dtype_logical));
169169
ca
170170
}
171171
}

crates/polars-core/src/chunked_array/collect.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub trait ChunkedCollectIterExt<T: PolarsDataType>: Iterator + Sized {
2727
where
2828
T::Array: ArrayFromIterDtype<Self::Item>,
2929
{
30-
let field = Arc::new(Field::new(name, dtype.clone()));
30+
let field = Arc::new(Field::new(name, dtype));
3131
let arr = self.collect_arr_with_dtype(field.dtype.to_arrow(CompatLevel::newest()));
3232
ChunkedArray::from_chunk_iter_and_field(field, [arr])
3333
}
@@ -48,7 +48,7 @@ pub trait ChunkedCollectIterExt<T: PolarsDataType>: Iterator + Sized {
4848
T::Array: ArrayFromIterDtype<Self::Item>,
4949
Self: TrustedLen,
5050
{
51-
let field = Arc::new(Field::new(name, dtype.clone()));
51+
let field = Arc::new(Field::new(name, dtype));
5252
let arr = self.collect_arr_trusted_with_dtype(field.dtype.to_arrow(CompatLevel::newest()));
5353
ChunkedArray::from_chunk_iter_and_field(field, [arr])
5454
}
@@ -74,7 +74,7 @@ pub trait ChunkedCollectIterExt<T: PolarsDataType>: Iterator + Sized {
7474
T::Array: ArrayFromIterDtype<U>,
7575
Self: Iterator<Item = Result<U, E>>,
7676
{
77-
let field = Arc::new(Field::new(name, dtype.clone()));
77+
let field = Arc::new(Field::new(name, dtype));
7878
let arr = self.try_collect_arr_with_dtype(field.dtype.to_arrow(CompatLevel::newest()))?;
7979
Ok(ChunkedArray::from_chunk_iter_and_field(field, [arr]))
8080
}
@@ -103,7 +103,7 @@ pub trait ChunkedCollectIterExt<T: PolarsDataType>: Iterator + Sized {
103103
T::Array: ArrayFromIterDtype<U>,
104104
Self: Iterator<Item = Result<U, E>> + TrustedLen,
105105
{
106-
let field = Arc::new(Field::new(name, dtype.clone()));
106+
let field = Arc::new(Field::new(name, dtype));
107107
let arr =
108108
self.try_collect_arr_trusted_with_dtype(field.dtype.to_arrow(CompatLevel::newest()))?;
109109
Ok(ChunkedArray::from_chunk_iter_and_field(field, [arr]))

crates/polars-core/src/chunked_array/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ pub(crate) mod test {
10201020
PlSmallStr::EMPTY,
10211021
CategoricalPhysical::U32,
10221022
);
1023-
let ca = ca.cast(&DataType::from_categories(cats.clone())).unwrap();
1023+
let ca = ca.cast(&DataType::from_categories(cats)).unwrap();
10241024
let ca = ca.cat32().unwrap();
10251025
let v: Vec<_> = ca.physical().into_iter().collect();
10261026
assert_eq!(v, &[Some(0), None, Some(1), Some(2)]);

crates/polars-core/src/chunked_array/ops/sort/categorical.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ mod test {
136136
PlSmallStr::EMPTY,
137137
CategoricalPhysical::U8,
138138
);
139-
let s =
140-
Series::new(PlSmallStr::EMPTY, init).cast(&DataType::from_categories(cats.clone()))?;
139+
let s = Series::new(PlSmallStr::EMPTY, init).cast(&DataType::from_categories(cats))?;
141140
let ca = s.cat8()?;
142141

143142
let out = ca.sort(false);
@@ -161,8 +160,7 @@ mod test {
161160
PlSmallStr::EMPTY,
162161
CategoricalPhysical::U8,
163162
);
164-
let series =
165-
Series::new(PlSmallStr::EMPTY, init).cast(&DataType::from_categories(cats.clone()))?;
163+
let series = Series::new(PlSmallStr::EMPTY, init).cast(&DataType::from_categories(cats))?;
166164

167165
let df = df![
168166
"cat" => &series,

crates/polars-core/src/datatypes/dtype.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,7 @@ mod tests {
12261226
fn test_unpack_primitive_dtypes() {
12271227
let inner_type = DataType::Float64;
12281228
let array_type = DataType::Array(Box::new(inner_type), 10);
1229-
let list_type = DataType::List(Box::new(array_type.clone()));
1229+
let list_type = DataType::List(Box::new(array_type));
12301230

12311231
let result = unpack_dtypes(&list_type, false);
12321232

@@ -1246,8 +1246,8 @@ mod tests {
12461246
let result = unpack_dtypes(&list_type, true);
12471247

12481248
let mut expected = PlHashSet::new();
1249-
expected.insert(list_type.clone());
1250-
expected.insert(array_type.clone());
1249+
expected.insert(list_type);
1250+
expected.insert(array_type);
12511251
expected.insert(DataType::Float64);
12521252

12531253
assert_eq!(result, expected)

crates/polars-core/src/fmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ impl Display for DataFrame {
713713
}
714714
}
715715
} else if height > 0 {
716-
let dots: Vec<String> = vec![ellipsis.clone(); self.columns.len()];
716+
let dots: Vec<String> = vec![ellipsis; self.columns.len()];
717717
table.add_row(dots);
718718
}
719719
let tbl_fallback_width = 100;

crates/polars-core/src/frame/explode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ mod test {
209209

210210
let s0 = Column::new(PlSmallStr::from_static("B"), [1, 2, 3]);
211211
let s1 = Column::new(PlSmallStr::from_static("C"), [1, 1, 1]);
212-
let df = DataFrame::new(vec![list, s0.clone(), s1.clone()]).unwrap();
212+
let df = DataFrame::new(vec![list, s0, s1]).unwrap();
213213
let exploded = df.explode(["foo"]).unwrap();
214214
assert_eq!(exploded.shape(), (9, 3));
215215
assert_eq!(

0 commit comments

Comments
 (0)