Skip to content

Commit b5f339d

Browse files
committed
ZJIT: Don't push frame for String#empty?
1 parent 63a58c7 commit b5f339d

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

zjit/src/cruby_methods.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ pub fn init() -> Annotations {
190190
annotate!(rb_mKernel, "itself", inline_kernel_itself);
191191
annotate!(rb_cString, "bytesize", types::Fixnum, no_gc, leaf);
192192
annotate!(rb_cString, "to_s", types::StringExact);
193+
annotate!(rb_cString, "empty?", types::BoolExact, no_gc, leaf, elidable);
193194
annotate!(rb_cModule, "name", types::StringExact.union(types::NilClass), no_gc, leaf, elidable);
194195
annotate!(rb_cModule, "===", types::BoolExact, no_gc, leaf);
195196
annotate!(rb_cArray, "length", types::Fixnum, no_gc, leaf, elidable);

zjit/src/hir.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12994,4 +12994,32 @@ mod opt_tests {
1299412994
Return v27
1299512995
");
1299612996
}
12997+
12998+
#[test]
12999+
fn test_string_empty() {
13000+
eval(r#"
13001+
def test(s)
13002+
s.empty?
13003+
end
13004+
test("asdf")
13005+
"#);
13006+
assert_snapshot!(hir_string("test"), @r"
13007+
fn test@<compiled>:3:
13008+
bb0():
13009+
EntryPoint interpreter
13010+
v1:BasicObject = LoadSelf
13011+
v2:BasicObject = GetLocal l0, SP@4
13012+
Jump bb2(v1, v2)
13013+
bb1(v5:BasicObject, v6:BasicObject):
13014+
EntryPoint JIT(0)
13015+
Jump bb2(v5, v6)
13016+
bb2(v8:BasicObject, v9:BasicObject):
13017+
PatchPoint MethodRedefined(String@0x1000, empty?@0x1008, cme:0x1010)
13018+
PatchPoint NoSingletonClass(String@0x1000)
13019+
v25:StringExact = GuardType v9, StringExact
13020+
v26:BoolExact = CCall empty?@0x1038, v25
13021+
CheckInterrupts
13022+
Return v26
13023+
");
13024+
}
1299713025
}

0 commit comments

Comments
 (0)