summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2021-03-21 00:11:08 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-03-21 00:11:08 +0900
commit298edfa4a29d4233fda2b42abdf93a0cd74928b9 (patch)
treedde39df7119af5e6caa8de3228c8257ee5ca212d /hash.c
parentcfadbf2fc4a6547f6e0bd47b8103c5b4bbd17b20 (diff)
Refactor hash aset callback
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c13
1 files changed, 3 insertions, 10 deletions
diff --git a/hash.c b/hash.c
index 378afa736a..adbcf082a3 100644
--- a/hash.c
+++ b/hash.c
@@ -1672,6 +1672,8 @@ struct update_arg {
VALUE old_value;
};
+static int hash_update_replace(st_data_t *key, st_data_t *value, struct update_arg *arg, int existing, st_data_t newvalue);
+
typedef int (*tbl_update_func)(st_data_t *, st_data_t *, st_data_t, int);
int
@@ -2837,16 +2839,7 @@ rb_hash_clear(VALUE hash)
static int
hash_aset(st_data_t *key, st_data_t *val, struct update_arg *arg, int existing)
{
- if (existing) {
- arg->new_value = arg->arg;
- arg->old_value = *val;
- }
- else {
- arg->new_key = *key;
- arg->new_value = arg->arg;
- }
- *val = arg->arg;
- return ST_CONTINUE;
+ return hash_update_replace(key, val, arg, existing, arg->arg);
}
VALUE