aboutsummaryrefslogtreecommitdiffstats
path: root/hash.c
diff options
context:
space:
mode:
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/hash.c b/hash.c
index 561aa90400..cab0b9eaa2 100644
--- a/hash.c
+++ b/hash.c
@@ -2862,6 +2862,30 @@ rb_hash_to_proc(VALUE hash)
return rb_func_proc_new(hash_proc_call, hash);
}
+static int
+add_new_i(st_data_t *key, st_data_t *val, st_data_t arg, int existing)
+{
+ VALUE *args = (VALUE *)arg;
+ if (existing) return ST_STOP;
+ RB_OBJ_WRITTEN(args[0], Qundef, (VALUE)*key);
+ RB_OBJ_WRITE(args[0], (VALUE *)val, args[1]);
+ return ST_CONTINUE;
+}
+
+/*
+ * add +key+ to +val+ pair if +hash+ does not contain +key+.
+ * returns non-zero if +key+ was contained.
+ */
+int
+rb_hash_add_new_element(VALUE hash, VALUE key, VALUE val)
+{
+ st_table *tbl = rb_hash_tbl_raw(hash);
+ VALUE args[2];
+ args[0] = hash;
+ args[1] = val;
+ return st_update(tbl, (st_data_t)key, add_new_i, (st_data_t)args);
+}
+
static int path_tainted = -1;
static char **origenviron;