Skip to content

Commit 9206ad5

Browse files
committed
Optimize Py<PyDict>::to_attributes() to reuse PyRefExact
1 parent 57fd8c9 commit 9206ad5

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

vm/src/builtins/dict.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{
22
set::PySetInner, IterStatus, PositionIterInternal, PyBaseExceptionRef, PyGenericAlias,
3-
PyMappingProxy, PySet, PyStrRef, PyTupleRef, PyType, PyTypeRef,
3+
PyMappingProxy, PySet, PyStr, PyTupleRef, PyType, PyTypeRef,
44
};
55
use crate::{
66
atomic_func,
@@ -534,9 +534,8 @@ impl Py<PyDict> {
534534
pub fn to_attributes(&self, vm: &VirtualMachine) -> PyAttributes {
535535
let mut attrs = PyAttributes::default();
536536
for (key, value) in self {
537-
// TODO: use PyRefExact for interning
538-
let key: PyStrRef = key.downcast().expect("dict has non-string keys");
539-
attrs.insert(vm.ctx.intern_str(key.as_str()), value);
537+
let key: PyRefExact<PyStr> = key.downcast_exact(vm).expect("dict has non-string keys");
538+
attrs.insert(vm.ctx.intern_str(key), value);
540539
}
541540
attrs
542541
}

0 commit comments

Comments
 (0)