diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-10-08 08:27:54 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-10-08 08:27:54 +0000 |
commit | c8d7d587ac11f3bea5cdac5a332b13bb9eb21447 (patch) | |
tree | 1ac40074650ee32b95350003cb0817839f78b484 /variable.c | |
parent | 02fe713b46a5f2365a2eccf0064b6116d7117e8e (diff) |
variable.c: use st_update
* variable.c (sv_i, cv_i): use st_update to insert non-existing
entries.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47847 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'variable.c')
-rw-r--r-- | variable.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/variable.c b/variable.c index b3ae3bdde7..0703d49d75 100644 --- a/variable.c +++ b/variable.c @@ -1964,6 +1964,14 @@ rb_const_remove(VALUE mod, ID id) } static int +cv_i_update(st_data_t *k, st_data_t *v, st_data_t a, int existing) +{ + if (existing) return ST_STOP; + *v = a; + return ST_CONTINUE; +} + +static int sv_i(st_data_t k, st_data_t v, st_data_t a) { ID key = (ID)k; @@ -1971,9 +1979,7 @@ sv_i(st_data_t k, st_data_t v, st_data_t a) st_table *tbl = (st_table *)a; if (rb_is_const_id(key)) { - if (!st_lookup(tbl, (st_data_t)key, 0)) { - st_insert(tbl, (st_data_t)key, (st_data_t)ce); - } + st_update(tbl, (st_data_t)key, cv_i_update, (st_data_t)ce); } return ST_CONTINUE; } @@ -2443,9 +2449,7 @@ cv_i(st_data_t k, st_data_t v, st_data_t a) st_table *tbl = (st_table *)a; if (rb_is_class_id(key)) { - if (!st_lookup(tbl, (st_data_t)key, 0)) { - st_insert(tbl, (st_data_t)key, 0); - } + st_update(tbl, (st_data_t)key, cv_i_update, 0); } return ST_CONTINUE; } |