diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-10-03 17:14:00 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-10-03 17:14:00 +0900 |
| commit | 09336c5d49481d56587f6e28924014954b4c8dd2 (patch) | |
| tree | 2929382ec25ac34578a3ae6ee77f2dafda7964dd /mrbgems/mruby-compiler/core/codegen.c | |
| parent | d64d8ca8e4515a2e03165401470ef109a6097e5d (diff) | |
| download | mruby-09336c5d49481d56587f6e28924014954b4c8dd2.tar.gz mruby-09336c5d49481d56587f6e28924014954b4c8dd2.zip | |
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.
Diffstat (limited to 'mrbgems/mruby-compiler/core/codegen.c')
| -rw-r--r-- | mrbgems/mruby-compiler/core/codegen.c | 4 |
1 files changed, 4 insertions, 0 deletions
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; |
