From 09336c5d49481d56587f6e28924014954b4c8dd2 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sun, 3 Oct 2021 17:14:00 +0900 Subject: mruby/ops.h: add new instructions `OP_GETIDX` and `OP_SETIDX`. Which represent `obj[int]` and `obj[int]=val` respectively where `obj` is either `string`, `array` or `hash`, so that index access could be faster. When `obj` is not assumed type or `R(a+1)` is not integer, the instructions fallback to method calls. --- mrbgems/mruby-compiler/core/codegen.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'mrbgems') diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c index 42c93debf..a142d21ad 100644 --- a/mrbgems/mruby-compiler/core/codegen.c +++ b/mrbgems/mruby-compiler/core/codegen.c @@ -832,6 +832,10 @@ static mrb_bool gen_binop(codegen_scope *s, mrb_sym op, uint16_t dst) { if (no_peephole(s)) return FALSE; + else if (op == MRB_OPSYM_2(s->mrb, aref)) { + genop_1(s, OP_GETIDX, dst); + return TRUE; + } else { struct mrb_insn_data data = mrb_last_insn(s); mrb_int n, n0; -- cgit v1.2.3