mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Rename rb_id_table_foreach_with_replace
Renames rb_id_table_foreach_with_replace to rb_id_table_foreach_values_with_replace and passes only the value to the callback. We can use this in GC compaction when we cannot access the global symbol array.
This commit is contained in:
parent
6e901939c6
commit
4d9ad91a35
Notes:
git
2022-01-26 06:51:38 +09:00
3 changed files with 30 additions and 30 deletions
14
gc.c
14
gc.c
|
@ -9790,7 +9790,7 @@ gc_ref_update_imemo(rb_objspace_t *objspace, VALUE obj)
|
|||
}
|
||||
|
||||
static enum rb_id_table_iterator_result
|
||||
check_id_table_move(ID id, VALUE value, void *data)
|
||||
check_id_table_move(VALUE value, void *data)
|
||||
{
|
||||
rb_objspace_t *objspace = (rb_objspace_t *)data;
|
||||
|
||||
|
@ -9835,7 +9835,7 @@ rb_gc_location(VALUE value)
|
|||
}
|
||||
|
||||
static enum rb_id_table_iterator_result
|
||||
update_id_table(ID *key, VALUE * value, void *data, int existing)
|
||||
update_id_table(VALUE *value, void *data, int existing)
|
||||
{
|
||||
rb_objspace_t *objspace = (rb_objspace_t *)data;
|
||||
|
||||
|
@ -9850,12 +9850,12 @@ static void
|
|||
update_m_tbl(rb_objspace_t *objspace, struct rb_id_table *tbl)
|
||||
{
|
||||
if (tbl) {
|
||||
rb_id_table_foreach_with_replace(tbl, check_id_table_move, update_id_table, objspace);
|
||||
rb_id_table_foreach_values_with_replace(tbl, check_id_table_move, update_id_table, objspace);
|
||||
}
|
||||
}
|
||||
|
||||
static enum rb_id_table_iterator_result
|
||||
update_cc_tbl_i(ID id, VALUE ccs_ptr, void *data)
|
||||
update_cc_tbl_i(VALUE ccs_ptr, void *data)
|
||||
{
|
||||
rb_objspace_t *objspace = (rb_objspace_t *)data;
|
||||
struct rb_class_cc_entries *ccs = (struct rb_class_cc_entries *)ccs_ptr;
|
||||
|
@ -9883,12 +9883,12 @@ update_cc_tbl(rb_objspace_t *objspace, VALUE klass)
|
|||
{
|
||||
struct rb_id_table *tbl = RCLASS_CC_TBL(klass);
|
||||
if (tbl) {
|
||||
rb_id_table_foreach_with_replace(tbl, update_cc_tbl_i, 0, objspace);
|
||||
rb_id_table_foreach_values_with_replace(tbl, update_cc_tbl_i, 0, objspace);
|
||||
}
|
||||
}
|
||||
|
||||
static enum rb_id_table_iterator_result
|
||||
update_cvc_tbl_i(ID id, VALUE cvc_entry, void *data)
|
||||
update_cvc_tbl_i(VALUE cvc_entry, void *data)
|
||||
{
|
||||
struct rb_cvar_class_tbl_entry *entry;
|
||||
|
||||
|
@ -9904,7 +9904,7 @@ update_cvc_tbl(rb_objspace_t *objspace, VALUE klass)
|
|||
{
|
||||
struct rb_id_table *tbl = RCLASS_CVC_TBL(klass);
|
||||
if (tbl) {
|
||||
rb_id_table_foreach_with_replace(tbl, update_cvc_tbl_i, 0, objspace);
|
||||
rb_id_table_foreach_values_with_replace(tbl, update_cvc_tbl_i, 0, objspace);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
42
id_table.c
42
id_table.c
|
@ -267,27 +267,6 @@ rb_id_table_delete(struct rb_id_table *tbl, ID id)
|
|||
return hash_delete_index(tbl, index);
|
||||
}
|
||||
|
||||
void
|
||||
rb_id_table_foreach_with_replace(struct rb_id_table *tbl, rb_id_table_foreach_func_t *func, rb_id_table_update_callback_func_t *replace, void *data)
|
||||
{
|
||||
int i, capa = tbl->capa;
|
||||
|
||||
for (i=0; i<capa; i++) {
|
||||
if (ITEM_KEY_ISSET(tbl, i)) {
|
||||
enum rb_id_table_iterator_result ret = (*func)((ID)0, tbl->items[i].val, data);
|
||||
assert(ITEM_GET_KEY(tbl, i));
|
||||
|
||||
if (ret == ID_TABLE_REPLACE) {
|
||||
VALUE val = tbl->items[i].val;
|
||||
ret = (*replace)(NULL, &val, data, TRUE);
|
||||
tbl->items[i].val = val;
|
||||
}
|
||||
else if (ret == ID_TABLE_STOP)
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
rb_id_table_foreach(struct rb_id_table *tbl, rb_id_table_foreach_func_t *func, void *data)
|
||||
{
|
||||
|
@ -323,3 +302,24 @@ rb_id_table_foreach_values(struct rb_id_table *tbl, rb_id_table_foreach_values_f
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
rb_id_table_foreach_values_with_replace(struct rb_id_table *tbl, rb_id_table_foreach_values_func_t *func, rb_id_table_update_value_callback_func_t *replace, void *data)
|
||||
{
|
||||
int i, capa = tbl->capa;
|
||||
|
||||
for (i = 0; i < capa; i++) {
|
||||
if (ITEM_KEY_ISSET(tbl, i)) {
|
||||
enum rb_id_table_iterator_result ret = (*func)(tbl->items[i].val, data);
|
||||
|
||||
if (ret == ID_TABLE_REPLACE) {
|
||||
VALUE val = tbl->items[i].val;
|
||||
ret = (*replace)(&val, data, TRUE);
|
||||
tbl->items[i].val = val;
|
||||
}
|
||||
else if (ret == ID_TABLE_STOP)
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,11 +26,11 @@ int rb_id_table_insert(struct rb_id_table *tbl, ID id, VALUE val);
|
|||
int rb_id_table_lookup(struct rb_id_table *tbl, ID id, VALUE *valp);
|
||||
int rb_id_table_delete(struct rb_id_table *tbl, ID id);
|
||||
|
||||
typedef enum rb_id_table_iterator_result rb_id_table_update_callback_func_t(ID *id, VALUE *val, void *data, int existing);
|
||||
typedef enum rb_id_table_iterator_result rb_id_table_update_value_callback_func_t(VALUE *val, void *data, int existing);
|
||||
typedef enum rb_id_table_iterator_result rb_id_table_foreach_func_t(ID id, VALUE val, void *data);
|
||||
typedef enum rb_id_table_iterator_result rb_id_table_foreach_values_func_t(VALUE val, void *data);
|
||||
void rb_id_table_foreach(struct rb_id_table *tbl, rb_id_table_foreach_func_t *func, void *data);
|
||||
void rb_id_table_foreach_with_replace(struct rb_id_table *tbl, rb_id_table_foreach_func_t *func, rb_id_table_update_callback_func_t *replace, void *data);
|
||||
void rb_id_table_foreach_values(struct rb_id_table *tbl, rb_id_table_foreach_values_func_t *func, void *data);
|
||||
void rb_id_table_foreach_values_with_replace(struct rb_id_table *tbl, rb_id_table_foreach_values_func_t *func, rb_id_table_update_value_callback_func_t *replace, void *data);
|
||||
|
||||
#endif /* RUBY_ID_TABLE_H */
|
||||
|
|
Loading…
Reference in a new issue