summaryrefslogtreecommitdiff
path: root/class.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-08 11:47:39 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-08 11:47:39 +0000
commit673aa230507d2c0d363dee81de83dab322f9c4ad (patch)
tree701a721b77875f20883530e22b042a147c0a2d9f /class.c
parent6def265d793d401f59d57349190fdd1974f166e4 (diff)
class.c: rest kwargs
* class.c (rb_get_kwargs): when values is non-null, remove extracted keywords from the rest keyword argument. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44077 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'class.c')
-rw-r--r--class.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/class.c b/class.c
index 5a4bf05..c7b3109 100644
--- a/class.c
+++ b/class.c
@@ -1914,6 +1914,12 @@ rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, V
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 ID *table, int required, int optional, V
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 ID *table, int required, int optional, V
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 ID *table, int required, int optional, V
}
}
return j;
+#undef extract_kwarg
}
/*!