MJIT: Refactor CDHASH handling

Converting a CDHASH into a safe Hash is a lot of work, but retrieving
just values is much easier.
This commit is contained in:
Takashi Kokubun 2022-11-29 00:12:29 -08:00
parent 44165df121
commit 8a0acbea4c
3 changed files with 4 additions and 49 deletions

View file

@ -544,12 +544,12 @@ class RubyVM::MJIT::Compiler
when /\A\s+JUMP\((?<dest>[^)]+)\);\s+\z/
dest = Regexp.last_match[:dest]
if insn.name == :opt_case_dispatch # special case... TODO: use another macro to avoid checking name
hash_offsets = C.rb_hash_values(operands[0])
else_offset = cast_offset(operands[1])
cdhash = C.cdhash_to_hash(operands[0])
base_pos = pos + insn_len
src << " switch (#{dest}) {\n"
cdhash.each do |_key, offset|
hash_offsets.each do |offset|
src << " case #{offset}:\n"
src << " goto label_#{base_pos + offset};\n"
end