Skip to content

Commit 154241c

Browse files
committed
refactor: simplified string conversion in event_hook_raw() and avoid a type cast that caused rust_analyzer to barf with an error (even though Rust compiles it)
1 parent ff8e06c commit 154241c

File tree

1 file changed

+5
-5
lines changed
  • gems/codetracer-ruby-recorder/ext/native_tracer/src

1 file changed

+5
-5
lines changed

gems/codetracer-ruby-recorder/ext/native_tracer/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -784,15 +784,15 @@ unsafe extern "C" fn event_hook_raw(data: VALUE, arg: *mut rb_trace_arg_t) {
784784
let ev: rb_event_flag_t = rb_tracearg_event_flag(arg);
785785
let path_val = rb_tracearg_path(arg);
786786
let line_val = rb_tracearg_lineno(arg);
787-
let path_bytes = if NIL_P(path_val) {
788-
&[] as &[u8]
787+
let path = if NIL_P(path_val) {
788+
""
789789
} else {
790-
std::slice::from_raw_parts(
790+
let path_bytes = std::slice::from_raw_parts(
791791
RSTRING_PTR(path_val) as *const u8,
792792
RSTRING_LEN(path_val) as usize,
793-
)
793+
);
794+
std::str::from_utf8(path_bytes).unwrap_or("")
794795
};
795-
let path = std::str::from_utf8(path_bytes).unwrap_or("");
796796
let line = rb_num2long(line_val) as i64;
797797
if should_ignore_path(path) {
798798
return;

0 commit comments

Comments
 (0)