Skip to content

Commit 7cb391e

Browse files
committed
Repalce all PyStr::from().into_ref(vm) with vm.ctx.empty_str
1 parent eba6833 commit 7cb391e

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

vm/src/exceptions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ impl PyBaseException {
507507
pub(super) fn str(&self, vm: &VirtualMachine) -> PyStrRef {
508508
let str_args = vm.exception_args_as_string(self.args(), true);
509509
match str_args.into_iter().exactly_one() {
510-
Err(i) if i.len() == 0 => PyStr::from("").into_ref(vm),
510+
Err(i) if i.len() == 0 => vm.ctx.empty_str.clone(),
511511
Ok(s) => s,
512512
Err(i) => PyStr::from(format!("({})", i.format(", "))).into_ref(vm),
513513
}

vm/src/frame.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ impl ExecutingFrame<'_> {
11251125

11261126
#[cfg_attr(feature = "flame-it", flame("Frame"))]
11271127
fn import(&mut self, vm: &VirtualMachine, module: Option<PyStrRef>) -> FrameResult {
1128-
let module = module.unwrap_or_else(|| PyStr::from("").into_ref(vm));
1128+
let module = module.unwrap_or_else(|| vm.ctx.empty_str.clone());
11291129
let from_list = <Option<PyTupleTyped<PyStrRef>>>::try_from_object(vm, self.pop_value())?;
11301130
let level = usize::try_from_object(vm, self.pop_value())?;
11311131

vm/src/stdlib/builtins.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ mod builtins {
305305
) -> PyResult<PyStrRef> {
306306
let format_spec = format_spec
307307
.into_option()
308-
.unwrap_or_else(|| PyStr::from("").into_ref(vm));
308+
.unwrap_or_else(|| vm.ctx.empty_str.clone());
309309

310310
call_object_format(vm, value, None, format_spec.as_str())
311311
}

vm/src/stdlib/io.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2588,7 +2588,7 @@ mod _io {
25882588
}
25892589
}
25902590
if chunks.is_empty() {
2591-
PyStr::from("").into_ref(vm)
2591+
vm.ctx.empty_str.clone()
25922592
} else if chunks.len() == 1 {
25932593
chunks.pop().unwrap()
25942594
} else {
@@ -2850,7 +2850,7 @@ mod _io {
28502850
} else if let Some(cur_line) = cur_line {
28512851
cur_line.slice_pystr(vm)
28522852
} else {
2853-
PyStr::from("").into_ref(vm)
2853+
vm.ctx.empty_str.clone()
28542854
};
28552855
Ok(line)
28562856
}
@@ -3009,7 +3009,7 @@ mod _io {
30093009
append: Option<PyStrRef>,
30103010
vm: &VirtualMachine,
30113011
) -> PyStrRef {
3012-
let empty_str = || PyStr::from("").into_ref(vm);
3012+
let empty_str = || vm.ctx.empty_str.clone();
30133013
let chars_pos = std::mem::take(&mut self.decoded_chars_used).bytes;
30143014
let decoded_chars = match std::mem::take(&mut self.decoded_chars) {
30153015
None => return append.unwrap_or_else(empty_str),

0 commit comments

Comments
 (0)