1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* hash.c: remove unnecessary checks for Qundef in hash iterations.

since hash use st_foreach_check for iterations, such checks are
  needless.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35193 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2012-03-31 04:20:45 +00:00
parent d4f379ad93
commit a3626110d9
3 changed files with 16 additions and 36 deletions

View file

@ -1,3 +1,9 @@
Sat Mar 31 13:20:40 2012 Sokolov Yura (funny-falcon) <funny.falcon@gmail.com>
* hash.c: remove unnecessary checks for Qundef in hash iterations.
since hash use st_foreach_check for iterations, such checks are
needless.
Sat Mar 31 12:05:01 2012 Martin Bosslet <Martin.Bosslet@googlemail.com>
* ext/openssl/ossl_x509cert.c: Fix doc typo.

View file

@ -42,10 +42,9 @@ numhash_aset(VALUE self, VALUE key, VALUE data)
}
static int
numhash_i(st_data_t key, st_data_t value, st_data_t arg, int error)
numhash_i(st_data_t key, st_data_t value, st_data_t arg)
{
VALUE ret;
if (key == 0 && value == 0 && error == 1) rb_raise(rb_eRuntimeError, "numhash modified");
ret = rb_yield_values(3, (VALUE)key, (VALUE)value, (VALUE)arg);
if (ret == Qtrue) return ST_CHECK;
return ST_CONTINUE;

43
hash.c
View file

@ -145,7 +145,7 @@ struct hash_foreach_arg {
};
static int
hash_foreach_iter(st_data_t key, st_data_t value, st_data_t argp, int err)
hash_foreach_iter(st_data_t key, st_data_t value, st_data_t argp)
{
struct hash_foreach_arg *arg = (struct hash_foreach_arg *)argp;
int status;
@ -437,7 +437,7 @@ rb_hash_rehash_i(VALUE key, VALUE value, VALUE arg)
{
st_table *tbl = (st_table *)arg;
if (key != Qundef) st_insert(tbl, (st_data_t)key, (st_data_t)value);
st_insert(tbl, (st_data_t)key, (st_data_t)value);
return ST_CONTINUE;
}
@ -874,7 +874,6 @@ rb_hash_shift(VALUE hash)
static int
delete_if_i(VALUE key, VALUE value, VALUE hash)
{
if (key == Qundef) return ST_CONTINUE;
if (RTEST(rb_yield_values(2, key, value))) {
rb_hash_delete_key(hash, key);
}
@ -972,7 +971,6 @@ rb_hash_values_at(int argc, VALUE *argv, VALUE hash)
static int
select_i(VALUE key, VALUE value, VALUE result)
{
if (key == Qundef) return ST_CONTINUE;
if (RTEST(rb_yield_values(2, key, value)))
rb_hash_aset(result, key, value);
return ST_CONTINUE;
@ -1006,7 +1004,6 @@ rb_hash_select(VALUE hash)
static int
keep_if_i(VALUE key, VALUE value, VALUE hash)
{
if (key == Qundef) return ST_CONTINUE;
if (!RTEST(rb_yield_values(2, key, value))) {
return ST_DELETE;
}
@ -1132,9 +1129,7 @@ rb_hash_aset(VALUE hash, VALUE key, VALUE val)
static int
replace_i(VALUE key, VALUE val, VALUE hash)
{
if (key != Qundef) {
rb_hash_aset(hash, key, val);
}
rb_hash_aset(hash, key, val);
return ST_CONTINUE;
}
@ -1215,7 +1210,6 @@ rb_hash_empty_p(VALUE hash)
static int
each_value_i(VALUE key, VALUE value)
{
if (key == Qundef) return ST_CONTINUE;
rb_yield(value);
return ST_CONTINUE;
}
@ -1250,7 +1244,6 @@ rb_hash_each_value(VALUE hash)
static int
each_key_i(VALUE key, VALUE value)
{
if (key == Qundef) return ST_CONTINUE;
rb_yield(key);
return ST_CONTINUE;
}
@ -1284,7 +1277,6 @@ rb_hash_each_key(VALUE hash)
static int
each_pair_i(VALUE key, VALUE value)
{
if (key == Qundef) return ST_CONTINUE;
rb_yield(rb_assoc_new(key, value));
return ST_CONTINUE;
}
@ -1322,7 +1314,6 @@ rb_hash_each_pair(VALUE hash)
static int
to_a_i(VALUE key, VALUE value, VALUE ary)
{
if (key == Qundef) return ST_CONTINUE;
rb_ary_push(ary, rb_assoc_new(key, value));
return ST_CONTINUE;
}
@ -1355,7 +1346,6 @@ inspect_i(VALUE key, VALUE value, VALUE str)
{
VALUE str2;
if (key == Qundef) return ST_CONTINUE;
str2 = rb_inspect(key);
if (RSTRING_LEN(str) > 1) {
rb_str_cat2(str, ", ");
@ -1422,7 +1412,6 @@ rb_hash_to_hash(VALUE hash)
static int
keys_i(VALUE key, VALUE value, VALUE ary)
{
if (key == Qundef) return ST_CONTINUE;
rb_ary_push(ary, key);
return ST_CONTINUE;
}
@ -1453,7 +1442,6 @@ rb_hash_keys(VALUE hash)
static int
values_i(VALUE key, VALUE value, VALUE ary)
{
if (key == Qundef) return ST_CONTINUE;
rb_ary_push(ary, value);
return ST_CONTINUE;
}
@ -1512,7 +1500,6 @@ rb_hash_search_value(VALUE key, VALUE value, VALUE arg)
{
VALUE *data = (VALUE *)arg;
if (key == Qundef) return ST_CONTINUE;
if (rb_equal(value, data[1])) {
data[0] = Qtrue;
return ST_STOP;
@ -1556,7 +1543,6 @@ eql_i(VALUE key, VALUE val1, VALUE arg)
struct equal_data *data = (struct equal_data *)arg;
st_data_t val2;
if (key == Qundef) return ST_CONTINUE;
if (!st_lookup(data->tbl, key, &val2)) {
data->result = Qfalse;
return ST_STOP;
@ -1658,7 +1644,6 @@ hash_i(VALUE key, VALUE val, VALUE arg)
st_index_t *hval = (st_index_t *)arg;
st_index_t hdata[2];
if (key == Qundef) return ST_CONTINUE;
hdata[0] = rb_hash(key);
hdata[1] = rb_hash(val);
*hval ^= st_hash(hdata, sizeof(hdata), 0);
@ -1699,7 +1684,6 @@ rb_hash_hash(VALUE hash)
static int
rb_hash_invert_i(VALUE key, VALUE value, VALUE hash)
{
if (key == Qundef) return ST_CONTINUE;
rb_hash_aset(hash, value, key);
return ST_CONTINUE;
}
@ -1728,7 +1712,6 @@ rb_hash_invert(VALUE hash)
static int
rb_hash_update_i(VALUE key, VALUE value, VALUE hash)
{
if (key == Qundef) return ST_CONTINUE;
hash_update(hash, key);
st_insert(RHASH(hash)->ntbl, key, value);
return ST_CONTINUE;
@ -1737,7 +1720,6 @@ rb_hash_update_i(VALUE key, VALUE value, VALUE hash)
static int
rb_hash_update_block_i(VALUE key, VALUE value, VALUE hash)
{
if (key == Qundef) return ST_CONTINUE;
if (rb_hash_has_key(hash, key)) {
value = rb_yield_values(3, key, rb_hash_aref(hash, key), value);
}
@ -1794,7 +1776,6 @@ rb_hash_update_func_i(VALUE key, VALUE value, VALUE arg0)
struct update_arg *arg = (struct update_arg *)arg0;
VALUE hash = arg->hash;
if (key == Qundef) return ST_CONTINUE;
if (rb_hash_has_key(hash, key)) {
value = (*arg->func)(key, rb_hash_aref(hash, key), value);
}
@ -1851,7 +1832,6 @@ assoc_i(VALUE key, VALUE val, VALUE arg)
{
VALUE *args = (VALUE *)arg;
if (key == Qundef) return ST_CONTINUE;
if (RTEST(rb_equal(args[0], key))) {
args[1] = rb_assoc_new(key, val);
return ST_STOP;
@ -1889,7 +1869,6 @@ rassoc_i(VALUE key, VALUE val, VALUE arg)
{
VALUE *args = (VALUE *)arg;
if (key == Qundef) return ST_CONTINUE;
if (RTEST(rb_equal(args[0], val))) {
args[1] = rb_assoc_new(key, val);
return ST_STOP;
@ -3086,11 +3065,9 @@ env_invert(void)
static int
env_replace_i(VALUE key, VALUE val, VALUE keys)
{
if (key != Qundef) {
env_aset(Qnil, key, val);
if (rb_ary_includes(keys, key)) {
rb_ary_delete(keys, key);
}
env_aset(Qnil, key, val);
if (rb_ary_includes(keys, key)) {
rb_ary_delete(keys, key);
}
return ST_CONTINUE;
}
@ -3122,12 +3099,10 @@ env_replace(VALUE env, VALUE hash)
static int
env_update_i(VALUE key, VALUE val)
{
if (key != Qundef) {
if (rb_block_given_p()) {
val = rb_yield_values(3, key, rb_f_getenv(Qnil, key), val);
}
env_aset(Qnil, key, val);
if (rb_block_given_p()) {
val = rb_yield_values(3, key, rb_f_getenv(Qnil, key), val);
}
env_aset(Qnil, key, val);
return ST_CONTINUE;
}