Skip to content

Commit 2291bdf

Browse files
committed
.
1 parent 61c372a commit 2291bdf

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

zjit/src/cruby_methods.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ pub fn init() -> Annotations {
219219
annotate!(rb_cString, "ascii_only?", types::BoolExact, no_gc, leaf);
220220
annotate!(rb_cModule, "name", types::StringExact.union(types::NilClass), no_gc, leaf, elidable);
221221
annotate!(rb_cModule, "===", inline_module_eqq, types::BoolExact, no_gc, leaf);
222-
annotate!(rb_cArray, "length", types::Fixnum, no_gc, leaf, elidable);
222+
annotate!(rb_cArray, "length", inline_array_length, types::Fixnum, no_gc, leaf, elidable);
223223
annotate!(rb_cArray, "size", types::Fixnum, no_gc, leaf, elidable);
224224
annotate!(rb_cArray, "empty?", types::BoolExact, no_gc, leaf, elidable);
225225
annotate!(rb_cArray, "reverse", types::ArrayExact, leaf, elidable);
@@ -537,6 +537,17 @@ fn inline_module_eqq(fun: &mut hir::Function, block: hir::BlockId, recv: hir::In
537537
None
538538
}
539539

540+
fn inline_array_length(fun: &mut hir::Function, block: hir::BlockId, recv: hir::InsnId, args: &[hir::InsnId], state: hir::InsnId) -> Option<hir::InsnId> {
541+
let &[] = args else { return None; };
542+
if fun.likely_a(recv, types::Array, state) {
543+
let recv = fun.coerce_to(block, recv, types::Array, state);
544+
let length_cint = fun.push_insn(block, hir::Insn::ArrayLength { array: recv });
545+
let result = fun.push_insn(block, hir::Insn::BoxFixnum { val: length_cint, state });
546+
return Some(result);
547+
}
548+
None
549+
}
550+
540551
fn inline_integer_succ(fun: &mut hir::Function, block: hir::BlockId, recv: hir::InsnId, args: &[hir::InsnId], state: hir::InsnId) -> Option<hir::InsnId> {
541552
if !args.is_empty() { return None; }
542553
if fun.likely_a(recv, types::Fixnum, state) {

0 commit comments

Comments
 (0)