Skip to content

Commit b08f415

Browse files
committed
remove useless refcount
1 parent 80afab5 commit b08f415

File tree

12 files changed

+23
-46
lines changed

12 files changed

+23
-46
lines changed

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ fn setup_main_module(vm: &VirtualMachine) -> PyResult<Scope> {
106106
.expect("Failed to initialize __main__.__annotations__");
107107

108108
vm.sys_module
109-
.clone()
110109
.get_attr("modules", vm)?
111110
.set_item("__main__", main_module, vm)?;
112111

src/shell.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ pub fn run_shell(vm: &VirtualMachine, scope: Scope) -> PyResult<()> {
105105
let prompt_name = if continuing { "ps2" } else { "ps1" };
106106
let prompt = vm
107107
.sys_module
108-
.clone()
109108
.get_attr(prompt_name, vm)
110109
.and_then(|prompt| prompt.str(vm));
111110
let prompt = match prompt {

vm/src/builtins/union.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ impl GetAttr for PyUnion {
278278
return zelf.as_object().generic_getattr(attr, vm);
279279
}
280280
}
281-
zelf.as_object().to_pyobject(vm).get_attr(attr, vm)
281+
zelf.as_object().get_attr(attr, vm)
282282
}
283283
}
284284

vm/src/codecs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,9 @@ fn normalize_encoding_name(encoding: &str) -> Cow<'_, str> {
359359

360360
// TODO: exceptions with custom payloads
361361
fn extract_unicode_error_range(err: &PyObject, vm: &VirtualMachine) -> PyResult<Range<usize>> {
362-
let start = err.to_owned().get_attr("start", vm)?;
362+
let start = err.get_attr("start", vm)?;
363363
let start = start.try_into_value(vm)?;
364-
let end = err.to_owned().get_attr("end", vm)?;
364+
let end = err.get_attr("end", vm)?;
365365
let end = end.try_into_value(vm)?;
366366
Ok(Range { start, end })
367367
}

vm/src/frame.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,11 +1155,7 @@ impl ExecutingFrame<'_> {
11551155
.map_err(|_| err())?;
11561156
let mod_name = mod_name.downcast::<PyStr>().map_err(|_| err())?;
11571157
let full_mod_name = format!("{mod_name}.{name}");
1158-
let sys_modules = vm
1159-
.sys_module
1160-
.clone()
1161-
.get_attr("modules", vm)
1162-
.map_err(|_| err())?;
1158+
let sys_modules = vm.sys_module.get_attr("modules", vm).map_err(|_| err())?;
11631159
sys_modules.get_item(&full_mod_name, vm).map_err(|_| err())
11641160
}
11651161

@@ -1459,7 +1455,7 @@ impl ExecutingFrame<'_> {
14591455
// FIXME: turn return type to PyResult<PyIterReturn> then ExecutionResult will be simplified
14601456
None if vm.is_none(&val) => PyIter::new(gen).next(vm),
14611457
None => {
1462-
let meth = gen.to_owned().get_attr("send", vm)?;
1458+
let meth = gen.get_attr("send", vm)?;
14631459
PyIterReturn::from_pyresult(meth.call((val,), vm), vm)
14641460
}
14651461
}
@@ -1744,7 +1740,6 @@ impl ExecutingFrame<'_> {
17441740

17451741
let displayhook = vm
17461742
.sys_module
1747-
.clone()
17481743
.get_attr("displayhook", vm)
17491744
.map_err(|_| vm.new_runtime_error("lost sys.displayhook".to_owned()))?;
17501745
displayhook.call((expr,), vm)?;

vm/src/protocol/object.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -357,16 +357,14 @@ impl PyObject {
357357
where
358358
F: Fn() -> String,
359359
{
360-
cls.to_owned()
361-
.get_attr(identifier!(vm, __bases__), vm)
362-
.map_err(|e| {
363-
// Only mask AttributeErrors.
364-
if e.class().is(vm.ctx.exceptions.attribute_error) {
365-
vm.new_type_error(msg())
366-
} else {
367-
e
368-
}
369-
})
360+
cls.get_attr(identifier!(vm, __bases__), vm).map_err(|e| {
361+
// Only mask AttributeErrors.
362+
if e.class().is(vm.ctx.exceptions.attribute_error) {
363+
vm.new_type_error(msg())
364+
} else {
365+
e
366+
}
367+
})
370368
}
371369

372370
fn abstract_issubclass(&self, cls: &PyObject, vm: &VirtualMachine) -> PyResult<bool> {

vm/src/stdlib/io.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ mod _io {
146146
}
147147

148148
fn ensure_unclosed(file: &PyObject, msg: &str, vm: &VirtualMachine) -> PyResult<()> {
149-
if file.to_owned().get_attr("closed", vm)?.try_to_bool(vm)? {
149+
if file.get_attr("closed", vm)?.try_to_bool(vm)? {
150150
Err(vm.new_value_error(msg.to_owned()))
151151
} else {
152152
Ok(())
@@ -324,7 +324,7 @@ mod _io {
324324
}
325325

326326
fn file_closed(file: &PyObject, vm: &VirtualMachine) -> PyResult<bool> {
327-
file.to_owned().get_attr("closed", vm)?.try_to_bool(vm)
327+
file.get_attr("closed", vm)?.try_to_bool(vm)
328328
}
329329
fn check_closed(file: &PyObject, vm: &VirtualMachine) -> PyResult<()> {
330330
if file_closed(file, vm)? {
@@ -1346,7 +1346,7 @@ mod _io {
13461346
}
13471347

13481348
pub fn repr_fileobj_name(obj: &PyObject, vm: &VirtualMachine) -> PyResult<Option<PyStrRef>> {
1349-
let name = match obj.to_owned().get_attr("name", vm) {
1349+
let name = match obj.get_attr("name", vm) {
13501350
Ok(name) => Some(name),
13511351
Err(e)
13521352
if e.fast_isinstance(vm.ctx.exceptions.attribute_error)
@@ -1506,24 +1506,15 @@ mod _io {
15061506
}
15071507
#[pygetset]
15081508
fn closed(&self, vm: &VirtualMachine) -> PyResult {
1509-
self.lock(vm)?
1510-
.check_init(vm)?
1511-
.to_owned()
1512-
.get_attr("closed", vm)
1509+
self.lock(vm)?.check_init(vm)?.get_attr("closed", vm)
15131510
}
15141511
#[pygetset]
15151512
fn name(&self, vm: &VirtualMachine) -> PyResult {
1516-
self.lock(vm)?
1517-
.check_init(vm)?
1518-
.to_owned()
1519-
.get_attr("name", vm)
1513+
self.lock(vm)?.check_init(vm)?.get_attr("name", vm)
15201514
}
15211515
#[pygetset]
15221516
fn mode(&self, vm: &VirtualMachine) -> PyResult {
1523-
self.lock(vm)?
1524-
.check_init(vm)?
1525-
.to_owned()
1526-
.get_attr("mode", vm)
1517+
self.lock(vm)?.check_init(vm)?.get_attr("mode", vm)
15271518
}
15281519
#[pymethod]
15291520
fn fileno(&self, vm: &VirtualMachine) -> PyResult {

vm/src/stdlib/os.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1803,7 +1803,7 @@ pub fn extend_module(vm: &VirtualMachine, module: &PyObject) {
18031803
let supports_dir_fd = PySet::default().into_ref(&vm.ctx);
18041804
let supports_follow_symlinks = PySet::default().into_ref(&vm.ctx);
18051805
for support in support_funcs {
1806-
let func_obj = module.to_owned().get_attr(support.name, vm).unwrap();
1806+
let func_obj = module.get_attr(support.name, vm).unwrap();
18071807
if support.fd.unwrap_or(false) {
18081808
supports_fd.clone().add(func_obj.clone(), vm).unwrap();
18091809
}

vm/src/stdlib/signal.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ pub(crate) mod _signal {
100100
}
101101

102102
let int_handler = module
103-
.clone()
104103
.get_attr("default_int_handler", vm)
105104
.expect("_signal does not have this attr?");
106105
if !vm.state.settings.no_sig_int {

vm/src/stdlib/sys.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -953,19 +953,16 @@ impl PyStderr<'_> {
953953

954954
pub fn get_stdin(vm: &VirtualMachine) -> PyResult {
955955
vm.sys_module
956-
.clone()
957956
.get_attr("stdin", vm)
958957
.map_err(|_| vm.new_runtime_error("lost sys.stdin".to_owned()))
959958
}
960959
pub fn get_stdout(vm: &VirtualMachine) -> PyResult {
961960
vm.sys_module
962-
.clone()
963961
.get_attr("stdout", vm)
964962
.map_err(|_| vm.new_runtime_error("lost sys.stdout".to_owned()))
965963
}
966964
pub fn get_stderr(vm: &VirtualMachine) -> PyResult {
967965
vm.sys_module
968-
.clone()
969966
.get_attr("stderr", vm)
970967
.map_err(|_| vm.new_runtime_error("lost sys.stderr".to_owned()))
971968
}

0 commit comments

Comments
 (0)