summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-03-04 10:14:40 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-03-04 10:14:40 +0000
commit6ac57385afa50e6df172d07a39b148a417d836b9 (patch)
treeea0e4ee58714aee78e094979ac331567cf106de0
parent78e8d67af165b6e031ed14c870b007db3515cb02 (diff)
downloadruby-6ac57385afa50e6df172d07a39b148a417d836b9.tar.gz
ruby-6ac57385afa50e6df172d07a39b148a417d836b9.tar.xz
ruby-6ac57385afa50e6df172d07a39b148a417d836b9.zip
* hash.c (rb_hash_aset): should not copy key string when
compare_by_identity is set. [ruby-dev:33604] git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@15687 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--hash.c13
2 files changed, 12 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index a7f4de32a..3bc621bd8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Tue Mar 4 19:10:43 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * hash.c (rb_hash_aset): should not copy key string when
+ compare_by_identity is set. [ruby-dev:33604]
+
Tue Mar 4 16:29:06 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* parse.y (parser_yylex): disallow non digits '0o' expression.
diff --git a/hash.c b/hash.c
index eca3e5c6a..3b74b8c20 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