Skip to content

Commit 6421e89

Browse files
XrXrk0kubun
authored andcommitted
DRY up IDs that have the same content as their name
1 parent f4283c6 commit 6421e89

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

zjit/src/cruby.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,19 +1138,20 @@ pub(crate) mod ids {
11381138
/// so reads can happen without `unsafe`. Synchronization done through
11391139
/// the VM lock.
11401140
macro_rules! def_ids {
1141-
($(name: $ident:ident content: $str:literal)*) => {
1141+
($(name: $name:ident $(content: $content:literal)?)*) => {
11421142
$(
1143-
#[doc = concat!("[type@crate::cruby::ID] for `", stringify!($str), "`")]
1144-
pub static $ident: AtomicU64 = AtomicU64::new(0);
1143+
pub static $name: AtomicU64 = AtomicU64::new(0);
11451144
)*
11461145

11471146
pub(crate) fn init() {
11481147
$(
1149-
let content = &$str;
1148+
let content = stringify!($name);
1149+
_ = content;
1150+
$(let content = &$content;)?
11501151
let ptr: *const u8 = content.as_ptr();
11511152

11521153
// Lookup and cache each ID
1153-
$ident.store(
1154+
$name.store(
11541155
unsafe { $crate::cruby::rb_intern2(ptr.cast(), content.len() as _) },
11551156
std::sync::atomic::Ordering::Relaxed
11561157
);
@@ -1163,12 +1164,12 @@ pub(crate) mod ids {
11631164
def_ids! {
11641165
name: NULL content: b""
11651166
name: respond_to_missing content: b"respond_to_missing?"
1166-
name: to_ary content: b"to_ary"
1167-
name: to_s content: b"to_s"
11681167
name: eq content: b"=="
11691168
name: include_p content: b"include?"
1170-
name: compile content: b"compile"
1171-
name: eval content: b"eval"
1169+
name: to_ary
1170+
name: to_s
1171+
name: compile
1172+
name: eval
11721173
}
11731174
}
11741175

0 commit comments

Comments
 (0)