summaryrefslogtreecommitdiff
path: root/variable.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-08 08:27:54 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-08 08:27:54 +0000
commitc8d7d587ac11f3bea5cdac5a332b13bb9eb21447 (patch)
tree1ac40074650ee32b95350003cb0817839f78b484 /variable.c
parent02fe713b46a5f2365a2eccf0064b6116d7117e8e (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.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/variable.c b/variable.c
index b3ae3bd..0703d49 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;
}