summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/hash.c b/hash.c
index eca3e5c6a2..3b74b8c20b 100644
--- a/hash.c
+++ b/hash.c
@@ -103,6 +103,11 @@ static const struct st_hash_type objhash = {
rb_any_hash,
};
+static const struct st_hash_type identhash = {
+ st_numcmp,
+ st_numhash,
+};
+
typedef int st_foreach_func(st_data_t, st_data_t, st_data_t);
struct foreach_safe_arg {
@@ -932,7 +937,8 @@ VALUE
rb_hash_aset(VALUE hash, VALUE key, VALUE val)
{
rb_hash_modify(hash);
- if (TYPE(key) != T_STRING || st_lookup(RHASH(hash)->ntbl, key, 0)) {
+ if (RHASH(hash)->ntbl->type == &identhash ||
+ TYPE(key) != T_STRING || st_lookup(RHASH(hash)->ntbl, key, 0)) {
st_insert(RHASH(hash)->ntbl, key, val);
}
else {
@@ -1685,11 +1691,6 @@ rb_hash_flatten(int argc, VALUE *argv, VALUE hash)
return ary;
}
-static const struct st_hash_type identhash = {
- st_numcmp,
- st_numhash,
-};
-
/*
* call-seq:
* hsh.compare_by_identity => hsh