Skip to content

Commit d12d286

Browse files
committed
Remove unnecessary python object creation
1 parent adad456 commit d12d286

2 files changed

Lines changed: 9 additions & 18 deletions

File tree

‎vm/src/builtins/builtinfunc.rs‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,10 @@ impl PyBuiltinFunction {
144144
format!("<built-in function {}>", self.value.name)
145145
}
146146
#[pyproperty(magic)]
147-
fn text_signature(&self, vm: &VirtualMachine) -> PyObjectRef {
148-
match self.value.doc.as_ref().and_then(|doc| {
147+
fn text_signature(&self) -> Option<String> {
148+
self.value.doc.as_ref().and_then(|doc| {
149149
pytype::get_text_signature_from_internal_doc(self.value.name.as_str(), doc.as_str())
150-
}) {
151-
Some(signature) => vm.ctx.new_str(signature),
152-
None => vm.ctx.none(),
153-
}
150+
})
154151
}
155152
}
156153

@@ -218,13 +215,10 @@ impl PyBuiltinMethod {
218215
self.value.doc.clone()
219216
}
220217
#[pyproperty(magic)]
221-
fn text_signature(&self, vm: &VirtualMachine) -> PyObjectRef {
222-
match self.value.doc.as_ref().and_then(|doc| {
218+
fn text_signature(&self) -> Option<String> {
219+
self.value.doc.as_ref().and_then(|doc| {
223220
pytype::get_text_signature_from_internal_doc(self.value.name.as_str(), doc.as_str())
224-
}) {
225-
Some(signature) => vm.ctx.new_str(signature),
226-
None => vm.ctx.none(),
227-
}
221+
})
228222
}
229223
#[pymethod(magic)]
230224
fn repr(&self) -> String {

‎vm/src/builtins/pytype.rs‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -519,15 +519,12 @@ impl PyType {
519519
}
520520

521521
#[pyproperty(magic)]
522-
fn text_signature(&self, vm: &VirtualMachine) -> PyObjectRef {
522+
fn text_signature(&self) -> Option<String> {
523523
let doc_string = self.get_attr("__doc__");
524524
let doc_string: Option<PyStrRef> = doc_string.and_then(|o| o.downcast().ok());
525-
match doc_string.and_then(|doc| {
525+
doc_string.and_then(|doc| {
526526
get_text_signature_from_internal_doc(self.name().as_str(), doc.as_str())
527-
}) {
528-
Some(doc) => vm.ctx.new_str(doc),
529-
_ => vm.ctx.none(),
530-
}
527+
})
531528
}
532529
}
533530

0 commit comments

Comments
 (0)