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

ruby-changes:31998

From: nobu <ko1@a...>
Date: Sun, 8 Dec 2013 20:47:46 +0900 (JST)
Subject: [ruby-changes:31998] nobu:r44077 (trunk): class.c: rest kwargs

nobu	2013-12-08 20:47:39 +0900 (Sun, 08 Dec 2013)

  New Revision: 44077

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

  Log:
    class.c: rest kwargs
    
    * class.c (rb_get_kwargs): when values is non-null, remove
      extracted keywords from the rest keyword argument.

  Modified files:
    trunk/ChangeLog
    trunk/class.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 44076)
+++ ChangeLog	(revision 44077)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Dec  8 20:47:35 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* class.c (rb_get_kwargs): when values is non-null, remove
+	  extracted keywords from the rest keyword argument.
+
 Sun Dec  8 20:26:54 2013  Yutaka Kanemoto  <kanemoto@r...>
 
 	* common.mk (ruby.imp): avoid circular dependency on AIX
Index: class.c
===================================================================
--- class.c	(revision 44076)
+++ class.c	(revision 44077)
@@ -1914,6 +1914,12 @@ rb_get_kwargs(VALUE keyword_hash, const https://github.com/ruby/ruby/blob/trunk/class.c#L1914
     int i = 0, j;
     int rest = 0;
     VALUE missing = Qnil;
+    st_data_t key;
+
+#define extract_kwarg(keyword, val) \
+    (key = (st_data_t)(keyword), values ? \
+     st_delete(rb_hash_tbl_raw(keyword_hash), &key, (val)) : \
+     st_lookup(rb_hash_tbl_raw(keyword_hash), key, (val)))
 
     if (optional < 0) {
 	rest = 1;
@@ -1929,7 +1935,7 @@ rb_get_kwargs(VALUE keyword_hash, const https://github.com/ruby/ruby/blob/trunk/class.c#L1935
 	    VALUE keyword = ID2SYM(table[i]);
 	    if (keyword_hash) {
 		st_data_t val;
-		if (st_lookup(rb_hash_tbl_raw(keyword_hash), (st_data_t)keyword, &val)) {
+		if (extract_kwarg(keyword, &val)) {
 		    if (values) values[i] = (VALUE)val;
 		    continue;
 		}
@@ -1945,7 +1951,7 @@ rb_get_kwargs(VALUE keyword_hash, const https://github.com/ruby/ruby/blob/trunk/class.c#L1951
     if (optional && keyword_hash) {
 	for (i = 0; i < optional; i++) {
 	    st_data_t val;
-	    if (st_lookup(rb_hash_tbl_raw(keyword_hash), ID2SYM(table[required+i]), &val)) {
+	    if (extract_kwarg(ID2SYM(table[required+i]), &val)) {
 		if (values) values[required+i] = (VALUE)val;
 		j++;
 	    }
@@ -1957,6 +1963,7 @@ rb_get_kwargs(VALUE keyword_hash, const https://github.com/ruby/ruby/blob/trunk/class.c#L1963
 	}
     }
     return j;
+#undef extract_kwarg
 }
 
 /*!

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

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