diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-09-24 13:43:58 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-09-24 13:43:58 +0000 |
commit | c1a432a7d9a9fee1b96c3af9889d86310e2d3ed7 (patch) | |
tree | c80cf50403da9548962e7cfbd8a55cfda3176d8f /hash.c | |
parent | 5f93fa308bd970eeab9a3028c44577f0af8c636c (diff) | |
download | ruby-c1a432a7d9a9fee1b96c3af9889d86310e2d3ed7.tar.gz |
* array.c (rb_ary_equal): should handle recursive array.
* hash.c (hash_equal): should handle recursive hash.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13509 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r-- | hash.c | 33 |
1 files changed, 14 insertions, 19 deletions
@@ -1350,8 +1350,9 @@ rb_hash_has_value(VALUE hash, VALUE val) } struct equal_data { - int result; + VALUE result; st_table *tbl; + int eql; }; static int @@ -1364,28 +1365,24 @@ eql_i(VALUE key, VALUE val1, struct equal_data *data) data->result = Qfalse; return ST_STOP; } - if (!rb_eql(val1, val2)) { + if (!(data->eql ? rb_eql(val1, val2) : rb_equal(val1, val2))) { data->result = Qfalse; return ST_STOP; } return ST_CONTINUE; } -static int -equal_i(VALUE key, VALUE val1, struct equal_data *data) +static VALUE +recursive_eql(VALUE hash, VALUE dt, int recur) { - VALUE val2; + struct equal_data *data; - if (key == Qundef) return ST_CONTINUE; - if (!st_lookup(data->tbl, key, &val2)) { - data->result = Qfalse; - return ST_STOP; - } - if (!rb_equal(val1, val2)) { - data->result = Qfalse; - return ST_STOP; - } - return ST_CONTINUE; + if (recur) return Qfalse; + data = (struct equal_data*)dt; + data->result = Qtrue; + rb_hash_foreach(hash, eql_i, (st_data_t)data); + + return data->result; } static VALUE @@ -1414,10 +1411,8 @@ hash_equal(VALUE hash1, VALUE hash2, int eql) #endif data.tbl = RHASH(hash2)->ntbl; - data.result = Qtrue; - rb_hash_foreach(hash1, eql ? eql_i : equal_i, (st_data_t)&data); - - return data.result; + data.eql = eql; + return rb_exec_recursive(recursive_eql, hash1, (VALUE)&data); } /* |