summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-07 16:19:47 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-07 16:19:47 +0000
commitcd6414267feba67f039d0a419ae91ae50ea26cd7 (patch)
treeee9d4154ddf29f3de94d3c1e113da4842b1ae47e
parentaaaab31d8b49244c0df11302788e8c5014909e23 (diff)
* hash.c (hash_i): make Hash#hash order insensitive.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16880 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--hash.c11
-rw-r--r--test/ruby/test_hash.rb4
3 files changed, 15 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index f33053f933a..e33c84eddcd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sun Jun 8 01:15:11 2008 Tanaka Akira <akr@fsij.org>
+
+ * hash.c (hash_i): make Hash#hash order insensitive.
+ (rb_hash_dup): use DUPSETUP.
+
Sat Jun 7 23:47:35 2008 Akinori MUSHA <knu@iDaemons.org>
* ext/zlib/zlib.c (rb_deflate_initialize, Init_zlib): Fix up
diff --git a/hash.c b/hash.c
index b6dc7bd66c5..4232ceeadf0 100644
--- a/hash.c
+++ b/hash.c
@@ -231,14 +231,16 @@ rb_hash_new(void)
VALUE
rb_hash_dup(VALUE hash)
{
- VALUE ret = hash_alloc(RBASIC(hash)->klass);
+ NEWOBJ(ret, struct RHash);
+ DUPSETUP(ret, hash);
+
if (!RHASH_EMPTY_P(hash))
- RHASH(ret)->ntbl = st_copy(RHASH(hash)->ntbl);
+ ret->ntbl = st_copy(RHASH(hash)->ntbl);
if (FL_TEST(hash, HASH_PROC_DEFAULT)) {
FL_SET(ret, HASH_PROC_DEFAULT);
}
- RHASH(ret)->ifnone = RHASH(hash)->ifnone;
- return ret;
+ ret->ifnone = RHASH(hash)->ifnone;
+ return (VALUE)ret;
}
static void
@@ -1470,7 +1472,6 @@ hash_i(VALUE key, VALUE val, int *hval)
{
if (key == Qundef) return ST_CONTINUE;
*hval ^= rb_hash(key);
- *hval *= 137;
*hval ^= rb_hash(val);
return ST_CONTINUE;
}
diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb
index c3acf14e3c1..c86cf3297d2 100644
--- a/test/ruby/test_hash.rb
+++ b/test/ruby/test_hash.rb
@@ -830,4 +830,8 @@ class TestHash < Test::Unit::TestCase
#assert_equal("bar", h[a])
assert_nil(h["foo"])
end
+
+ def test_hash_hash
+ assert_equal({0=>2,11=>1}.hash, {11=>1,0=>2}.hash)
+ end
end