diff --git a/ext/liquid_c/vm.c b/ext/liquid_c/vm.c index f24a2334..7755c1ee 100644 --- a/ext/liquid_c/vm.c +++ b/ext/liquid_c/vm.c @@ -235,15 +235,11 @@ static VALUE vm_render_until_error(VALUE uncast_args) const uint8_t *ip = args->ip; vm_t *vm = args->vm; VALUE output = args->output; + uint16_t constant_index; VALUE constant = Qnil; args->ip = NULL; // used by vm_render_rescue, NULL to indicate that it isn't in a rescue block while (true) { - if (vm_assembler_opcode_has_constant(*ip)) { - uint16_t constant_index = (ip[1] << 8) | ip[2]; - constant = constants[constant_index]; - } - switch (*ip++) { case OP_LEAVE: return false; @@ -271,6 +267,8 @@ static VALUE vm_render_until_error(VALUE uncast_args) } case OP_FIND_STATIC_VAR: { + constant_index = (ip[0] << 8) | ip[1]; + constant = constants[constant_index]; ip += 2; VALUE value = context_find_variable(&vm->context, constant, Qtrue); vm_stack_push(vm, value); @@ -286,6 +284,8 @@ static VALUE vm_render_until_error(VALUE uncast_args) case OP_LOOKUP_CONST_KEY: case OP_LOOKUP_COMMAND: { + constant_index = (ip[0] << 8) | ip[1]; + constant = constants[constant_index]; ip += 2; vm_stack_push(vm, constant); } @@ -325,6 +325,8 @@ static VALUE vm_render_until_error(VALUE uncast_args) uint8_t num_args; if (ip[-1] == OP_FILTER) { + constant_index = (ip[0] << 8) | ip[1]; + constant = constants[constant_index]; filter_name = RARRAY_AREF(constant, 0); num_args = RARRAY_AREF(constant, 1); ip += 2; @@ -376,6 +378,8 @@ static VALUE vm_render_until_error(VALUE uncast_args) case OP_PUSH_CONST: { + constant_index = (ip[0] << 8) | ip[1]; + constant = constants[constant_index]; ip += 2; vm_stack_push(vm, constant); break; @@ -383,6 +387,8 @@ static VALUE vm_render_until_error(VALUE uncast_args) case OP_WRITE_NODE: { + constant_index = (ip[0] << 8) | ip[1]; + constant = constants[constant_index]; ip += 2; rb_funcall(cLiquidBlockBody, id_render_node, 3, vm->context.self, output, constant);