Skip to content

Commit 9dab8cd

Browse files
tekknolagik0kubun
authored andcommitted
Remove Option from get_class_name parameter
1 parent 308cd59 commit 9dab8cd

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

zjit/src/hir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ impl<'a> std::fmt::Display for InvariantPrinter<'a> {
151151
write!(f, ")")
152152
}
153153
Invariant::MethodRedefined { klass, method } => {
154-
let class_name = get_class_name(Some(klass));
154+
let class_name = get_class_name(klass);
155155
let method_name = unsafe {
156156
cstr_to_rust_string(rb_id2name(method)).unwrap_or_else(|| "<unknown>".to_owned())
157157
};

zjit/src/hir_type/mod.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,15 @@ pub struct Type {
6464
include!("hir_type.inc.rs");
6565

6666
/// Get class name from a class pointer.
67-
pub fn get_class_name(class: Option<VALUE>) -> String {
67+
pub fn get_class_name(class: VALUE) -> String {
6868
use crate::cruby::{RB_TYPE_P, RUBY_T_MODULE, RUBY_T_CLASS};
6969
use crate::cruby::{cstr_to_rust_string, rb_class2name};
70-
class.filter(|&class| {
71-
// type checks for rb_class2name()
72-
unsafe { RB_TYPE_P(class, RUBY_T_MODULE) || RB_TYPE_P(class, RUBY_T_CLASS) }
73-
}).and_then(|class| unsafe {
70+
// type checks for rb_class2name()
71+
if unsafe { RB_TYPE_P(class, RUBY_T_MODULE) || RB_TYPE_P(class, RUBY_T_CLASS) } {
72+
Some(class)
73+
} else {
74+
None
75+
}.and_then(|class| unsafe {
7476
cstr_to_rust_string(rb_class2name(class))
7577
}).unwrap_or_else(|| "Unknown".to_string())
7678
}
@@ -80,8 +82,8 @@ fn write_spec(f: &mut std::fmt::Formatter, printer: &TypePrinter) -> std::fmt::R
8082
match ty.spec {
8183
Specialization::Any | Specialization::Empty => { Ok(()) },
8284
Specialization::Object(val) => write!(f, "[{}]", val.print(printer.ptr_map)),
83-
Specialization::Type(val) => write!(f, "[class:{}]", get_class_name(Some(val))),
84-
Specialization::TypeExact(val) => write!(f, "[class_exact:{}]", get_class_name(Some(val))),
85+
Specialization::Type(val) => write!(f, "[class:{}]", get_class_name(val)),
86+
Specialization::TypeExact(val) => write!(f, "[class_exact:{}]", get_class_name(val)),
8587
Specialization::Int(val) if ty.is_subtype(types::CBool) => write!(f, "[{}]", val != 0),
8688
Specialization::Int(val) if ty.is_subtype(types::CInt8) => write!(f, "[{}]", (val as i64) >> 56),
8789
Specialization::Int(val) if ty.is_subtype(types::CInt16) => write!(f, "[{}]", (val as i64) >> 48),

0 commit comments

Comments
 (0)