ruby-changes:23143
From: nobu <ko1@a...>
Date: Sat, 31 Mar 2012 13:21:43 +0900 (JST)
Subject: [ruby-changes:23143] nobu:r35193 (trunk): * hash.c: remove unnecessary checks for Qundef in hash iterations.
nobu 2012-03-31 13:20:45 +0900 (Sat, 31 Mar 2012) New Revision: 35193 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=35193 Log: * hash.c: remove unnecessary checks for Qundef in hash iterations. since hash use st_foreach_check for iterations, such checks are needless. Modified files: trunk/ChangeLog trunk/ext/-test-/st/numhash/numhash.c trunk/hash.c Index: ChangeLog =================================================================== --- ChangeLog (revision 35192) +++ ChangeLog (revision 35193) @@ -1,3 +1,9 @@ +Sat Mar 31 13:20:40 2012 Sokolov Yura (funny-falcon) <funny.falcon@g...> + + * 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@g...> * ext/openssl/ossl_x509cert.c: Fix doc typo. Index: ext/-test-/st/numhash/numhash.c =================================================================== --- ext/-test-/st/numhash/numhash.c (revision 35192) +++ ext/-test-/st/numhash/numhash.c (revision 35193) @@ -42,10 +42,9 @@ } 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; Index: hash.c =================================================================== --- hash.c (revision 35192) +++ hash.c (revision 35193) @@ -145,7 +145,7 @@ }; 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 @@ { 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ { 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 @@ 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 @@ 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 @@ { 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ { 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 @@ { 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 @@ 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 @@ 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; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/