Skip to content

Commit 33f8f18

Browse files
committed
Only provide function name to CallContext in debug
1 parent 97259b6 commit 33f8f18

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

check.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ while [[ $# -gt 0 ]]; do
205205
echo "$HELP_TEXT"
206206
exit 0
207207
;;
208+
--release)
209+
extraCargoArgs+=("--release")
210+
;;
208211
--use-serde)
209212
extraCargoArgs+=("--features" "serde")
210213
;;

godot-core/src/builtin/callable.rs

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

639-
let name = {
639+
#[cfg(debug_assertions)]
640+
let name = &{
640641
let c: &C = CallableUserdata::inner_from_raw(callable_userdata);
641642
c.to_string()
642643
};
643-
let ctx = meta::CallContext::custom_callable(name.as_str());
644+
#[cfg(not(debug_assertions))]
645+
let name = "<optimized out>";
646+
let ctx = meta::CallContext::custom_callable(name);
644647

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

666-
let name = {
669+
#[cfg(debug_assertions)]
670+
let name = &{
667671
let w: &FnWrapper<F> = CallableUserdata::inner_from_raw(callable_userdata);
668672
w.name.to_string()
669673
};
670-
let ctx = meta::CallContext::custom_callable(name.as_str());
674+
#[cfg(not(debug_assertions))]
675+
let name = "<optimized out>";
676+
let ctx = meta::CallContext::custom_callable(name);
671677

672678
crate::private::handle_varcall_panic(&ctx, &mut *r_error, move || {
673679
// 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_local_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)