From c8d7d587ac11f3bea5cdac5a332b13bb9eb21447 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 8 Oct 2014 08:27:54 +0000 Subject: [PATCH] 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 --- variable.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/variable.c b/variable.c index b3ae3bdde7..0703d49d75 100644 --- a/variable.c +++ b/variable.c @@ -1963,6 +1963,14 @@ rb_const_remove(VALUE mod, ID id) return val; } +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) { @@ -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; }