Skip to content

Commit 4615a2d

Browse files
authored
Enable clone_on_ref_ptr clippy lint on execution crate (#11239)
1 parent 4aa584c commit 4615a2d

File tree

7 files changed

+18
-13
lines changed

7 files changed

+18
-13
lines changed

datafusion/execution/src/cache/cache_manager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ impl CacheManager {
5454
pub fn try_new(config: &CacheManagerConfig) -> Result<Arc<Self>> {
5555
let mut manager = CacheManager::default();
5656
if let Some(cc) = &config.table_files_statistics_cache {
57-
manager.file_statistic_cache = Some(cc.clone())
57+
manager.file_statistic_cache = Some(Arc::clone(cc))
5858
}
5959
if let Some(lc) = &config.list_files_cache {
60-
manager.list_files_cache = Some(lc.clone())
60+
manager.list_files_cache = Some(Arc::clone(lc))
6161
}
6262
Ok(Arc::new(manager))
6363
}

datafusion/execution/src/cache/cache_unit.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl CacheAccessor<Path, Arc<Statistics>> for DefaultFileStatisticsCache {
3939
fn get(&self, k: &Path) -> Option<Arc<Statistics>> {
4040
self.statistics
4141
.get(k)
42-
.map(|s| Some(s.value().1.clone()))
42+
.map(|s| Some(Arc::clone(&s.value().1)))
4343
.unwrap_or(None)
4444
}
4545

@@ -55,7 +55,7 @@ impl CacheAccessor<Path, Arc<Statistics>> for DefaultFileStatisticsCache {
5555
// file has changed
5656
None
5757
} else {
58-
Some(statistics.clone())
58+
Some(Arc::clone(statistics))
5959
}
6060
})
6161
.unwrap_or(None)
@@ -108,7 +108,7 @@ impl CacheAccessor<Path, Arc<Vec<ObjectMeta>>> for DefaultListFilesCache {
108108
type Extra = ObjectMeta;
109109

110110
fn get(&self, k: &Path) -> Option<Arc<Vec<ObjectMeta>>> {
111-
self.statistics.get(k).map(|x| x.value().clone())
111+
self.statistics.get(k).map(|x| Arc::clone(x.value()))
112112
}
113113

114114
fn get_with_extra(

datafusion/execution/src/disk_manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl DiskManager {
139139

140140
let dir_index = thread_rng().gen_range(0..local_dirs.len());
141141
Ok(RefCountedTempFile {
142-
parent_temp_dir: local_dirs[dir_index].clone(),
142+
parent_temp_dir: Arc::clone(&local_dirs[dir_index]),
143143
tempfile: Builder::new()
144144
.tempfile_in(local_dirs[dir_index].as_ref())
145145
.map_err(DataFusionError::IoError)?,

datafusion/execution/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
// KIND, either express or implied. See the License for the
1515
// specific language governing permissions and limitations
1616
// under the License.
17+
// Make cheap clones clear: https://github.com/apache/datafusion/issues/11143
18+
#![deny(clippy::clone_on_ref_ptr)]
1719

1820
//! DataFusion execution configuration and runtime structures
1921

datafusion/execution/src/memory_pool/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,15 +268,15 @@ impl MemoryReservation {
268268
self.size = self.size.checked_sub(capacity).unwrap();
269269
Self {
270270
size: capacity,
271-
registration: self.registration.clone(),
271+
registration: Arc::clone(&self.registration),
272272
}
273273
}
274274

275275
/// Returns a new empty [`MemoryReservation`] with the same [`MemoryConsumer`]
276276
pub fn new_empty(&self) -> Self {
277277
Self {
278278
size: 0,
279-
registration: self.registration.clone(),
279+
registration: Arc::clone(&self.registration),
280280
}
281281
}
282282

datafusion/execution/src/object_store.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl ObjectStoreRegistry for DefaultObjectStoreRegistry {
234234
let s = get_url_key(url);
235235
self.object_stores
236236
.get(&s)
237-
.map(|o| o.value().clone())
237+
.map(|o| Arc::clone(o.value()))
238238
.ok_or_else(|| {
239239
DataFusionError::Internal(format!(
240240
"No suitable object store found for {url}. See `RuntimeEnv::register_object_store`"

datafusion/execution/src/task.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl TaskContext {
121121

122122
/// Return the [RuntimeEnv] associated with this [TaskContext]
123123
pub fn runtime_env(&self) -> Arc<RuntimeEnv> {
124-
self.runtime.clone()
124+
Arc::clone(&self.runtime)
125125
}
126126

127127
/// Update the [`SessionConfig`]
@@ -172,19 +172,22 @@ impl FunctionRegistry for TaskContext {
172172
udaf: Arc<AggregateUDF>,
173173
) -> Result<Option<Arc<AggregateUDF>>> {
174174
udaf.aliases().iter().for_each(|alias| {
175-
self.aggregate_functions.insert(alias.clone(), udaf.clone());
175+
self.aggregate_functions
176+
.insert(alias.clone(), Arc::clone(&udaf));
176177
});
177178
Ok(self.aggregate_functions.insert(udaf.name().into(), udaf))
178179
}
179180
fn register_udwf(&mut self, udwf: Arc<WindowUDF>) -> Result<Option<Arc<WindowUDF>>> {
180181
udwf.aliases().iter().for_each(|alias| {
181-
self.window_functions.insert(alias.clone(), udwf.clone());
182+
self.window_functions
183+
.insert(alias.clone(), Arc::clone(&udwf));
182184
});
183185
Ok(self.window_functions.insert(udwf.name().into(), udwf))
184186
}
185187
fn register_udf(&mut self, udf: Arc<ScalarUDF>) -> Result<Option<Arc<ScalarUDF>>> {
186188
udf.aliases().iter().for_each(|alias| {
187-
self.scalar_functions.insert(alias.clone(), udf.clone());
189+
self.scalar_functions
190+
.insert(alias.clone(), Arc::clone(&udf));
188191
});
189192
Ok(self.scalar_functions.insert(udf.name().into(), udf))
190193
}

0 commit comments

Comments
 (0)