mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 21:49:06 +02:00
Introduce a specialize instruction for Array#pack
Instructions for this code: ```ruby # frozen_string_literal: true [a].pack("C") ``` Before this commit: ``` == disasm: #<ISeq:<main>@test.rb:1 (1,0)-(3,13)> 0000 putself ( 3)[Li] 0001 opt_send_without_block <calldata!mid:a, argc:0, FCALL|VCALL|ARGS_SIMPLE> 0003 newarray 1 0005 putobject "C" 0007 opt_send_without_block <calldata!mid:pack, argc:1, ARGS_SIMPLE> 0009 leave ``` After this commit: ``` == disasm: #<ISeq:<main>@test.rb:1 (1,0)-(3,13)> 0000 putself ( 3)[Li] 0001 opt_send_without_block <calldata!mid:a, argc:0, FCALL|VCALL|ARGS_SIMPLE> 0003 putobject "C" 0005 opt_newarray_send 2, :pack 0008 leave ``` Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com> Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
This commit is contained in:
parent
e5e079e70f
commit
49fcd33e13
15 changed files with 132 additions and 5 deletions
13
array.c
13
array.c
|
@ -880,6 +880,19 @@ rb_ary_free(VALUE ary)
|
|||
}
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_setup_fake_ary(struct RArray *fake_ary, const VALUE *list, long len, bool freeze)
|
||||
{
|
||||
fake_ary->basic.flags = T_ARRAY;
|
||||
VALUE ary = (VALUE)fake_ary;
|
||||
RBASIC_CLEAR_CLASS(ary);
|
||||
ARY_SET_PTR(ary, list);
|
||||
ARY_SET_HEAP_LEN(ary, len);
|
||||
ARY_SET_CAPA(ary, len);
|
||||
if (freeze) OBJ_FREEZE(ary);
|
||||
return ary;
|
||||
}
|
||||
|
||||
size_t
|
||||
rb_ary_memsize(VALUE ary)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue