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

ruby-changes:37533

From: nobu <ko1@a...>
Date: Mon, 16 Feb 2015 20:59:09 +0900 (JST)
Subject: [ruby-changes:37533] nobu:r49614 (trunk): compile.c: massign optimization

nobu	2015-02-16 20:58:52 +0900 (Mon, 16 Feb 2015)

  New Revision: 49614

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49614

  Log:
    compile.c: massign optimization
    
    * compile.c (compile_massign): optimization for special case,
      assignments by aset or attrset.
      http://kokizzu.blogspot.jp/2015/02/c-java-hhvm-ruby-nodejsrhinojscspidermo.html
      http://www.atdot.net/~ko1/diary/201502.html#d16

  Modified files:
    trunk/ChangeLog
    trunk/compile.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 49613)
+++ ChangeLog	(revision 49614)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Feb 16 20:58:49 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* compile.c (compile_massign): optimization for special case,
+	  assignments by aset or attrset.
+	  http://kokizzu.blogspot.jp/2015/02/c-java-hhvm-ruby-nodejsrhinojscspidermo.html
+	  http://www.atdot.net/~ko1/diary/201502.html#d16
+
 Sun Feb 15 10:41:23 2015  Sho Hashimoto  <sho-h@r...>
 
 	* doc/standard_library.rdoc: [DOC] delete removed libraries.
Index: compile.c
===================================================================
--- compile.c	(revision 49613)
+++ compile.c	(revision 49614)
@@ -2782,6 +2782,7 @@ compile_massign(rb_iseq_t *iseq, LINK_AN https://github.com/ruby/ruby/blob/trunk/compile.c#L2782
 
     if (!poped || splatn || !compile_massign_opt(iseq, ret, rhsn, lhsn)) {
 	int llen = 0;
+	int expand = 1;
 	DECL_ANCHOR(lhsseq);
 
 	INIT_ANCHOR(lhsseq);
@@ -2797,9 +2798,30 @@ compile_massign(rb_iseq_t *iseq, LINK_AN https://github.com/ruby/ruby/blob/trunk/compile.c#L2798
 	if (!poped) {
 	    ADD_INSN(ret, nd_line(node), dup);
 	}
-
-	ADD_INSN2(ret, nd_line(node), expandarray,
-		  INT2FIX(llen), INT2FIX(lhs_splat));
+	else if (!lhs_splat) {
+	    INSN *last = (INSN*)ret->last;
+	    if (last->link.type == ISEQ_ELEMENT_INSN &&
+		last->insn_id == BIN(newarray) &&
+		last->operand_size == 1 &&
+		OPERAND_AT(last, 0) == INT2FIX(llen)) {
+		/* special case: assign to aset or attrset */
+		if (llen == 2) {
+		    POP_ELEMENT(ret);
+		    ADD_INSN(ret, nd_line(node), swap);
+		    expand = 0;
+		}
+#if 0
+		else if (llen > 2) {
+		    last->insn_id = BIN(reverse);
+		    expand = 0;
+		}
+#endif
+	    }
+	}
+	if (expand) {
+	    ADD_INSN2(ret, nd_line(node), expandarray,
+		      INT2FIX(llen), INT2FIX(lhs_splat));
+	}
 	ADD_SEQ(ret, lhsseq);
 
 	if (lhs_splat) {

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

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