summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compile.c7
-rw-r--r--insns.def23
-rw-r--r--test/ruby/test_jit.rb4
3 files changed, 18 insertions, 16 deletions
diff --git a/compile.c b/compile.c
index d97cf4e8c6..b9a17fde3e 100644
--- a/compile.c
+++ b/compile.c
@@ -3984,7 +3984,12 @@ compile_array(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node_ro
ADD_INSN1(ret, line, duparray, ary);
}
else { /* COMPILE_ARRAY_TYPE_HASH */
- ADD_INSN2(ret, line, newhashfromarray, INT2FIX(RARRAY_LEN(ary)/2), ary);
+ VALUE hash;
+
+ hash = rb_hash_new_with_size(RARRAY_LEN(ary) / 2);
+ rb_hash_bulk_insert(RARRAY_LEN(ary), RARRAY_CONST_PTR_TRANSIENT(ary), hash);
+ iseq_add_mark_object_compile_time(iseq, hash);
+ ADD_INSN1(ret, line, duphash, hash);
}
}
else {
diff --git a/insns.def b/insns.def
index efd5bb74a2..73628a3376 100644
--- a/insns.def
+++ b/insns.def
@@ -454,6 +454,16 @@ duparray
val = rb_ary_resurrect(ary);
}
+/* dup hash */
+DEFINE_INSN
+duphash
+(VALUE hash)
+()
+(VALUE val)
+{
+ val = rb_hash_dup(hash);
+}
+
/* if TOS is an array expand, expand it to num objects.
if the number of the array is less than num, push nils to fill.
if it is greater than num, exceeding elements are dropped.
@@ -514,19 +524,6 @@ newhash
}
}
-/* make new Hash object from (frozen) Array object */
-DEFINE_INSN
-newhashfromarray
-(rb_num_t num, VALUE ary)
-()
-(VALUE hash)
-// attr bool leaf = false; /* rb_hash_bulk_insert() can call methods. */
-{
- VM_ASSERT(num * 2 == (rb_num_t)RARRAY_LEN(ary));
- hash = rb_hash_new_with_size(num);
- rb_hash_bulk_insert(num * 2, RARRAY_CONST_PTR_TRANSIENT(ary), hash);
-}
-
/* put new Range object.(Range.new(low, high, flag)) */
DEFINE_INSN
newrange
diff --git a/test/ruby/test_jit.rb b/test/ruby/test_jit.rb
index fdcb0726ef..7627b2c048 100644
--- a/test/ruby/test_jit.rb
+++ b/test/ruby/test_jit.rb
@@ -239,8 +239,8 @@ class TestJIT < Test::Unit::TestCase
assert_compile_once('a = 1; { a: a }', result_inspect: '{:a=>1}', insns: %i[newhash])
end
- def test_compile_insn_newhashfromarray
- assert_compile_once('{ a: 1 }', result_inspect: '{:a=>1}', insns: %i[newhashfromarray])
+ def test_compile_insn_duphash
+ assert_compile_once('{ a: 1 }', result_inspect: '{:a=>1}', insns: %i[duphash])
end
def test_compile_insn_newrange