Skip to content

Commit 2932cbc

Browse files
committed
Only provide function name to CallContext in debug
1 parent 4a58210 commit 2932cbc

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

godot-core/src/builtin/callable.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -654,11 +654,14 @@ mod custom_callable {
654654
) {
655655
let arg_refs: &[&Variant] = Variant::borrow_ref_slice(p_args, p_argument_count as usize);
656656

657-
let name = {
657+
#[cfg(debug_assertions)]
658+
let name = &{
658659
let c: &C = CallableUserdata::inner_from_raw(callable_userdata);
659660
c.to_string()
660661
};
661-
let ctx = meta::CallContext::custom_callable(name.as_str());
662+
#[cfg(not(debug_assertions))]
663+
let name = "<optimized out>";
664+
let ctx = meta::CallContext::custom_callable(name);
662665

663666
crate::private::handle_varcall_panic(&ctx, &mut *r_error, move || {
664667
// Get the RustCallable again inside closure so it doesn't have to be UnwindSafe.
@@ -681,11 +684,14 @@ mod custom_callable {
681684
{
682685
let arg_refs: &[&Variant] = Variant::borrow_ref_slice(p_args, p_argument_count as usize);
683686

684-
let name = {
687+
#[cfg(debug_assertions)]
688+
let name = &{
685689
let w: &FnWrapper<F> = CallableUserdata::inner_from_raw(callable_userdata);
686690
w.name.to_string()
687691
};
688-
let ctx = meta::CallContext::custom_callable(name.as_str());
692+
#[cfg(not(debug_assertions))]
693+
let name = "<optimized out>";
694+
let ctx = meta::CallContext::custom_callable(name);
689695

690696
crate::private::handle_varcall_panic(&ctx, &mut *r_error, move || {
691697
// Get the FnWrapper again inside closure so the FnMut doesn't have to be UnwindSafe.

itest/rust/src/benchmarks/mod.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use godot::builtin::inner::InnerRect2i;
1313
use godot::builtin::{GString, PackedInt32Array, Rect2i, StringName, Vector2i};
1414
use godot::classes::{Node3D, Os, RefCounted};
1515
use godot::obj::{Gd, InstanceId, NewAlloc, NewGd, Singleton};
16+
use godot::prelude::{varray, Callable, RustCallable, Variant};
1617
use godot::register::GodotClass;
1718

1819
use crate::framework::bench;
@@ -113,9 +114,36 @@ fn packed_array_from_iter_unknown_size() -> PackedInt32Array {
113114
}))
114115
}
115116

117+
#[bench(repeat = 25)]
118+
fn call_callv_rust_fn() -> Variant {
119+
let callable = Callable::from_fn("RustFunction", |_| ());
120+
callable.callv(&varray![])
121+
}
122+
123+
#[bench(repeat = 25)]
124+
fn call_callv_custom() -> Variant {
125+
let callable = Callable::from_custom(MyRustCallable {});
126+
callable.callv(&varray![])
127+
}
128+
116129
// ----------------------------------------------------------------------------------------------------------------------------------------------
117130
// Helpers for benchmarks above
118131

119132
#[derive(GodotClass)]
120133
#[class(init)]
121134
struct MyBenchType {}
135+
136+
#[derive(PartialEq, Hash)]
137+
struct MyRustCallable {}
138+
139+
impl RustCallable for MyRustCallable {
140+
fn invoke(&mut self, _args: &[&Variant]) -> Variant {
141+
Variant::nil()
142+
}
143+
}
144+
145+
impl std::fmt::Display for MyRustCallable {
146+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
147+
write!(f, "MyRustCallable")
148+
}
149+
}

0 commit comments

Comments
 (0)