From 2f0ea052387d3f951c2cae7ec5d5fc1f4b8e2a67 Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Wed, 28 Aug 2024 09:19:21 +0200 Subject: [PATCH] avoid clone in replace_sort_expressions --- datafusion/expr/src/tree_node.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/datafusion/expr/src/tree_node.rs b/datafusion/expr/src/tree_node.rs index 0aba9c4af1c0e..c7c498dd3f017 100644 --- a/datafusion/expr/src/tree_node.rs +++ b/datafusion/expr/src/tree_node.rs @@ -404,11 +404,11 @@ pub fn transform_sort_vec Result>>( pub fn replace_sort_expressions(sorts: Vec, new_expr: Vec) -> Vec { assert_eq!(sorts.len(), new_expr.len()); - let mut new_sorts = Vec::with_capacity(sorts.len()); - for (i, expr) in new_expr.into_iter().enumerate() { - new_sorts.push(replace_sort_expression(sorts[i].clone(), expr)); - } - new_sorts + sorts + .into_iter() + .zip(new_expr) + .map(|(sort, expr)| replace_sort_expression(sort, expr)) + .collect() } pub fn replace_sort_expression(sort: Sort, new_expr: Expr) -> Sort {