@@ -2446,6 +2446,22 @@ gen_opt_regexpmatch2(jitstate_t *jit, ctx_t *ctx)
24462446 return gen_opt_send_without_block (jit , ctx );
24472447}
24482448
2449+ static codegen_status_t
2450+ gen_opt_case_dispatch (jitstate_t * jit , ctx_t * ctx )
2451+ {
2452+ // Normally this instruction would lookup the key in a hash and jump to an
2453+ // offset based on that.
2454+ // Instead we can take the fallback case and continue with the next
2455+ // instruciton.
2456+ // We'd hope that our jitted code will be sufficiently fast without the
2457+ // hash lookup, at least for small hashes, but it's worth revisiting this
2458+ // assumption in the future.
2459+
2460+ ctx_stack_pop (ctx , 1 );
2461+
2462+ return YJIT_KEEP_COMPILING ; // continue with the next instruction
2463+ }
2464+
24492465void
24502466gen_branchif_branch (codeblock_t * cb , uint8_t * target0 , uint8_t * target1 , uint8_t shape )
24512467{
@@ -4214,6 +4230,7 @@ yjit_init_codegen(void)
42144230 yjit_reg_op (BIN (opt_getinlinecache ), gen_opt_getinlinecache );
42154231 yjit_reg_op (BIN (opt_invokebuiltin_delegate ), gen_opt_invokebuiltin_delegate );
42164232 yjit_reg_op (BIN (opt_invokebuiltin_delegate_leave ), gen_opt_invokebuiltin_delegate );
4233+ yjit_reg_op (BIN (opt_case_dispatch ), gen_opt_case_dispatch );
42174234 yjit_reg_op (BIN (branchif ), gen_branchif );
42184235 yjit_reg_op (BIN (branchunless ), gen_branchunless );
42194236 yjit_reg_op (BIN (branchnil ), gen_branchnil );
0 commit comments