Slide 36
Slide 36 text
Change: Skip #deconstruct checks
when obj is a Array
Does’nt Pattern have constant or has const and the const eq obj
Does obj has #deconstruct?
Does obj#deconstruct return a Array object?
The result of obj#deconstruct’s(or value of itself) length is
equal to Pattern’s one?
Check if each element of Pattern ===
each element of the result of obj#deconstruct (or value of itself)
Y
Y
Y
Y
Is Obj an Array?
- LABEL *match_failed, *type_error, *deconstruct, *deconstructed;
+ LABEL *match_failed, *type_error, *deconstruct, *deconstructed,
*skip_deconstruct;
int i;
match_failed = NEW_LABEL(line);
type_error = NEW_LABEL(line);
deconstruct = NEW_LABEL(line);
deconstructed = NEW_LABEL(line);
+ skip_deconstruct = NEW_LABEL(line);
if (use_rest_num) {
ADD_INSN1(ret, line_node, putobject, INT2FIX(0)); /* allocate stack for
rest_num */
@@ -6439,9 +6440,19 @@ iseq_compile_pattern_each(rb_iseq_t *iseq, LINK_ANCHOR
*const ret, const NODE *c
CHECK(iseq_compile_pattern_constant(iseq, ret, node, match_failed,
in_single_pattern, base_index));
+ //skip deconstuct and use obj value when obj is array.
+ ADD_INSN(ret, line_node, dup);
+ ADD_INSN1(ret, line_node, checktype, INT2FIX(T_ARRAY));
+ ADD_INSNL(ret, line_node, branchif, skip_deconstruct);
CHECK(iseq_compile_array_deconstruct(iseq, ret, node, deconstruct,
deconstructed, match_failed, type_error, in_single_pattern, base_index,
use_deconstructed_cache));
+ ADD_LABEL(ret, skip_deconstruct);
N
diff of compile.c