mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
add setter of iter_lev.
* hash.c: add special setter function (inc and dec). * internal.h: constify RHash::iter_leve. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66765 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
140f8b94ce
commit
e3dbe84e12
2 changed files with 16 additions and 4 deletions
18
hash.c
18
hash.c
|
@ -1206,17 +1206,29 @@ hash_foreach_iter(st_data_t key, st_data_t value, st_data_t argp, int error)
|
|||
return ST_CHECK;
|
||||
}
|
||||
|
||||
static void
|
||||
hash_iter_lev_inc(VALUE hash)
|
||||
{
|
||||
*((int *)&RHASH(hash)->iter_lev) = RHASH_ITER_LEV(hash) + 1;
|
||||
}
|
||||
|
||||
static void
|
||||
hash_iter_lev_dec(VALUE hash)
|
||||
{
|
||||
*((int *)&RHASH(hash)->iter_lev) = RHASH_ITER_LEV(hash) - 1;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
hash_foreach_ensure_rollback(VALUE hash)
|
||||
{
|
||||
RHASH_ITER_LEV(hash)++;
|
||||
hash_iter_lev_inc(hash);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
hash_foreach_ensure(VALUE hash)
|
||||
{
|
||||
RHASH_ITER_LEV(hash)--;
|
||||
hash_iter_lev_dec(hash);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1257,7 +1269,7 @@ rb_hash_foreach(VALUE hash, int (*func)(ANYARGS), VALUE farg)
|
|||
|
||||
if (RHASH_TABLE_EMPTY_P(hash))
|
||||
return;
|
||||
RHASH_ITER_LEV(hash)++;
|
||||
hash_iter_lev_inc(hash);
|
||||
arg.hash = hash;
|
||||
arg.func = (rb_foreach_func *)func;
|
||||
arg.arg = farg;
|
||||
|
|
|
@ -806,7 +806,7 @@ struct RHash {
|
|||
st_table *st;
|
||||
struct ar_table_struct *ar; /* possibly 0 */
|
||||
} as;
|
||||
int iter_lev;
|
||||
const int iter_lev;
|
||||
const VALUE ifnone;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue