* 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
This commit is contained in:
parent
aaaab31d8b
commit
cd6414267f
@ -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
|
||||
|
11
hash.c
11
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;
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user