[前][次][番号順一覧][スレッド一覧]

ruby-changes:57642

From: Yusuke <ko1@a...>
Date: Sat, 7 Sep 2019 16:31:56 +0900 (JST)
Subject: [ruby-changes:57642] 2f2f8107d0 (master): compile.c (compile_list): allow an odd-length hidden array literal

https://git.ruby-lang.org/ruby.git/commit/?id=2f2f8107d0

From 2f2f8107d0d21f5ebaaaf3b2d7ed6d09dfec91d5 Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@r...>
Date: Sat, 7 Sep 2019 16:26:38 +0900
Subject: compile.c (compile_list): allow an odd-length hidden array literal

An array literal [1,2,...,301] was compiled to the following iseq:

  duparray [1,2,...,300]
  putobject [301]
  concatarray

The Array literal optimization took every two elements maybe because it
must handle not only Array but also Hash.
Now the optimization takes each element if it is an Array literal.  So
the new iseq is: duparray [1,2,...,301].

diff --git a/compile.c b/compile.c
index 43a1038..10dff7c 100644
--- a/compile.c
+++ b/compile.c
@@ -3987,16 +3987,25 @@ compile_list(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node_roo https://github.com/ruby/ruby/blob/trunk/compile.c#L3987
                         rb_ary_push(ary, static_literal_value(node, iseq));
 			node = node->nd_next;
 		    }
-		    while (node && node->nd_next &&
-                           static_literal_node_p(node, iseq) &&
-                           static_literal_node_p(node->nd_next, iseq)) {
-			VALUE elem[2];
-                        elem[0] = static_literal_value(node, iseq);
-                        elem[1] = static_literal_value(node->nd_next, iseq);
-			rb_ary_cat(ary, elem, 2);
-			node = node->nd_next->nd_next;
-			len++;
-		    }
+                    if (type == COMPILE_ARRAY_TYPE_ARRAY) {
+                        while (node && static_literal_node_p(node, iseq)) {
+                            rb_ary_push(ary, static_literal_value(node, iseq));
+                            node = node->nd_next;
+                            len++;
+                        }
+                    }
+                    else { /* COMPILE_ARRAY_TYPE_HASH */
+                        while (node && node->nd_next &&
+                               static_literal_node_p(node, iseq) &&
+                               static_literal_node_p(node->nd_next, iseq)) {
+                            VALUE elem[2];
+                            elem[0] = static_literal_value(node, iseq);
+                            elem[1] = static_literal_value(node->nd_next, iseq);
+                            rb_ary_cat(ary, elem, 2);
+                            node = node->nd_next->nd_next;
+                            len++;
+                        }
+                    }
 
 		    OBJ_FREEZE(ary);
 
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]