Remove redundant clone · RustPython/RustPython@74253e2 · GitHub
Skip to content

Commit 74253e2

Browse files
committed
Remove redundant clone
1 parent c6c1ec5 commit 74253e2

20 files changed

Lines changed: 55 additions & 73 deletions

vm/src/builtins.rs

Lines changed: 7 additions & 11 deletions

vm/src/bytesinner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl ByteInnerNewOptions {
8686
// Only one argument
8787
} else {
8888
let value = if let OptionalArg::Present(ival) = self.val_option {
89-
match_class!(match ival.clone() {
89+
match_class!(match ival {
9090
i @ PyInt => {
9191
let size =
9292
objint::get_value(&i.into_object())

vm/src/cformat.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,9 @@ impl CFormatSpec {
292292
let result = match preconversor {
293293
CFormatPreconversor::Str => vm.to_str(&obj)?,
294294
CFormatPreconversor::Repr | CFormatPreconversor::Ascii => vm.to_repr(&obj)?,
295-
CFormatPreconversor::Bytes => TryFromObject::try_from_object(
296-
vm,
297-
vm.call_method(&obj.clone(), "decode", vec![])?,
298-
)?,
295+
CFormatPreconversor::Bytes => {
296+
TryFromObject::try_from_object(vm, vm.call_method(&obj, "decode", vec![])?)?
297+
}
299298
};
300299
Ok(self.format_string(result.borrow_value().to_owned()))
301300
}

vm/src/frame.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,7 +1394,7 @@ impl ExecutingFrame<'_> {
13941394
needle: PyObjectRef,
13951395
haystack: PyObjectRef,
13961396
) -> PyResult<bool> {
1397-
let found = vm._membership(haystack.clone(), needle)?;
1397+
let found = vm._membership(haystack, needle)?;
13981398
Ok(objbool::boolval(vm, found)?)
13991399
}
14001400

@@ -1404,7 +1404,7 @@ impl ExecutingFrame<'_> {
14041404
needle: PyObjectRef,
14051405
haystack: PyObjectRef,
14061406
) -> PyResult<bool> {
1407-
let found = vm._membership(haystack.clone(), needle)?;
1407+
let found = vm._membership(haystack, needle)?;
14081408
Ok(!objbool::boolval(vm, found)?)
14091409
}
14101410

vm/src/import.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ pub fn init_importlib(vm: &mut VirtualMachine, initialize_parameter: InitParamet
2525
match initialize_parameter {
2626
InitParameter::InitializeExternal if cfg!(feature = "rustpython-compiler") => {
2727
flame_guard!("install_external");
28-
let install_external =
29-
vm.get_attribute(importlib.clone(), "_install_external_importers")?;
28+
let install_external = vm.get_attribute(importlib, "_install_external_importers")?;
3029
vm.invoke(&install_external, vec![])?;
3130
// Set pyc magic number to commit hash. Should be changed when bytecode will be more stable.
3231
let importlib_external = vm.import("_frozen_importlib_external", &[], 0)?;

vm/src/obj/objbool.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub fn boolval(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<bool> {
5353

5454
get_value(&bool_obj)
5555
}
56-
None => match vm.get_method(obj.clone(), "__len__") {
56+
None => match vm.get_method(obj, "__len__") {
5757
Some(method_or_err) => {
5858
let method = method_or_err?;
5959
let bool_obj = vm.invoke(&method, PyFuncArgs::default())?;
@@ -120,7 +120,7 @@ impl PyBool {
120120
let rhs = get_value(&rhs);
121121
(lhs || rhs).into_pyobject(vm)
122122
} else {
123-
get_py_int(&lhs).or(rhs.clone(), vm).into_pyobject(vm)
123+
get_py_int(&lhs).or(rhs, vm).into_pyobject(vm)
124124
}
125125
}
126126

@@ -134,7 +134,7 @@ impl PyBool {
134134
let rhs = get_value(&rhs);
135135
(lhs && rhs).into_pyobject(vm)
136136
} else {
137-
get_py_int(&lhs).and(rhs.clone(), vm).into_pyobject(vm)
137+
get_py_int(&lhs).and(rhs, vm).into_pyobject(vm)
138138
}
139139
}
140140

@@ -148,7 +148,7 @@ impl PyBool {
148148
let rhs = get_value(&rhs);
149149
(lhs ^ rhs).into_pyobject(vm)
150150
} else {
151-
get_py_int(&lhs).xor(rhs.clone(), vm).into_pyobject(vm)
151+
get_py_int(&lhs).xor(rhs, vm).into_pyobject(vm)
152152
}
153153
}
154154

@@ -162,7 +162,7 @@ impl PyBool {
162162
)));
163163
}
164164
let val = match x {
165-
OptionalArg::Present(val) => boolval(vm, val.clone())?,
165+
OptionalArg::Present(val) => boolval(vm, val)?,
166166
OptionalArg::Missing => false,
167167
};
168168
Ok(vm.ctx.new_bool(val))

vm/src/obj/objclassmethod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,7 @@ impl PyClassMethod {
6666
callable: PyObjectRef,
6767
vm: &VirtualMachine,
6868
) -> PyResult<PyClassMethodRef> {
69-
PyClassMethod {
70-
callable: callable.clone(),
71-
}
72-
.into_ref_with_type(vm, cls)
69+
PyClassMethod { callable }.into_ref_with_type(vm, cls)
7370
}
7471

7572
#[pyproperty(name = "__func__")]

vm/src/obj/objdict.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ impl PyDictRef {
341341

342342
#[pymethod(name = "__ior__")]
343343
fn ior(self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult {
344-
let dicted: Result<PyDictRef, _> = other.clone().downcast();
344+
let dicted: Result<PyDictRef, _> = other.downcast();
345345
if let Ok(other) = dicted {
346346
PyDictRef::merge_dict(&self.entries, other, vm)?;
347347
return Ok(self.into_object());
@@ -351,7 +351,7 @@ impl PyDictRef {
351351

352352
#[pymethod(name = "__ror__")]
353353
fn ror(self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyDict> {
354-
let dicted: Result<PyDictRef, _> = other.clone().downcast();
354+
let dicted: Result<PyDictRef, _> = other.downcast();
355355
if let Ok(other) = dicted {
356356
let other_cp = other.copy();
357357
PyDictRef::merge_dict(&other_cp.entries, self, vm)?;
@@ -362,7 +362,7 @@ impl PyDictRef {
362362

363363
#[pymethod(name = "__or__")]
364364
fn or(self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyDict> {
365-
let dicted: Result<PyDictRef, _> = other.clone().downcast();
365+
let dicted: Result<PyDictRef, _> = other.downcast();
366366
if let Ok(other) = dicted {
367367
let self_cp = self.copy();
368368
PyDictRef::merge_dict(&self_cp.entries, other, vm)?;

vm/src/obj/objfilter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl PyFilter {
3535
let iterator = objiter::get_iter(vm, &iterable)?;
3636

3737
PyFilter {
38-
predicate: function.clone(),
38+
predicate: function,
3939
iterator,
4040
}
4141
.into_ref_with_type(vm, cls)

vm/src/obj/objlist.rs

Lines changed: 2 additions & 2 deletions

0 commit comments

Comments
 (0)