summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 f33053f933..e33c84eddc 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 b6dc7bd66c..4232ceeadf 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 c3acf14e3c..c86cf3297d 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