-
-
Notifications
You must be signed in to change notification settings - Fork 249
Use rust str instead of cstr in ClassIdSource
#1334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-1334 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, nice simplification! 🙂
110ff74
to
71fd5c7
Compare
e8ca64a
to
0d57a89
Compare
Clippy CI failed strangely, but I can't reproduce it locally. |
it is because the file in question is formatted differently on CI (it is oooneee big line). Why? No idea (details of macro formatting are black magic to me, sorry 🤷). Code in question as it is formatted on mine and beicause's sides #[func]
fn check_last_notrace(last_method_name: String, expected_callconv: String) -> bool {
let last = godot::private::trace::pop();
let mut ok = true;
if last.class != "GenFfi" {
godot_error!("Expected class GenFfi, got {}", last.class);
ok = false;
}
if last.method != last_method_name {
godot_error!("Expected method {}, got {}", last_method_name, last.method);
ok = false;
}
if !last.is_inbound {
godot_error!("Expected inbound call, got outbound");
ok = false;
}
let expect_ptrcall = expected_callconv == "ptrcall";
if last.is_ptrcall != expect_ptrcall {
let actual = Self::to_string(last.is_ptrcall);
godot_error!("Expected {expected_callconv}, got {actual}");
ok = false;
}
ok
} To elaborate, this code: fn check(a: bool, b: bool, c: bool) -> bool {
let mut godot_error = false;
if a {
println!("a");
godot_error = true;
}
if b {
println!("b");
godot_error = true;
}
if c {
println!("c");
godot_error = true;
}
godot_error
} is fine and triggers no clippy warnings, meanwhile fn check(a: bool, b: bool, c: bool) -> bool {
let mut godot_error = false;
if a {
println!("a");
godot_error = true;
} if b {
println!("b");
godot_error = true;
}
if c {
println!("c");
godot_error = true;
}
godot_error
} triggers following warning: Checking playground v0.0.1 (/playground)
warning: this looks like an `else if` but the `else` is missing
--> src/main.rs:6:6
|
6 | } if b {
| ^
|
= note: to remove this lint, add the missing `else` or add a new line before the second `if`
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_else_formatting
= note: `#[warn(clippy::suspicious_else_formatting)]` on by default |
EDIT: I'll address it, in this case simple |
0d57a89
to
82feab1
Compare
Replace `ClassIdSource` with `Cow<'static, str>`
82feab1
to
63b942e
Compare
This simplifies things and improves performance of
ClassId::to_cow_str
, which is overhead inCallContext::gd
andcheck_rtti
.I think the only reason for using cstr might be initializing StringName from it is slightly faster than rust str, but this is not a hot path since initialization only happens once.