diff options
author | Peter Zhu <peter@peterzhu.ca> | 2022-01-25 16:11:24 -0500 |
---|---|---|
committer | Peter Zhu <peter@peterzhu.ca> | 2022-01-25 16:51:16 -0500 |
commit | 4d9ad91a35b16afde38fd4ae513a49d22e27b3ea (patch) | |
tree | d3c57dcaf33ea2310ca8e6195a739a0342c16cd1 | |
parent | 6e901939c67d7c1275c183b0bde4d5d1c78ef081 (diff) | |
download | ruby-4d9ad91a35b16afde38fd4ae513a49d22e27b3ea.tar.gz |
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.
-rw-r--r-- | gc.c | 14 | ||||
-rw-r--r-- | id_table.c | 42 | ||||
-rw-r--r-- | id_table.h | 4 |
3 files changed, 30 insertions, 30 deletions
@@ -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); } } diff --git a/id_table.c b/id_table.c index b2ba6fae89..6cf4af9c5f 100644 --- a/id_table.c +++ b/id_table.c @@ -268,27 +268,6 @@ rb_id_table_delete(struct rb_id_table *tbl, ID id) } 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) { int i, capa = tbl->capa; @@ -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; + } + } +} + diff --git a/id_table.h b/id_table.h index f3dc681d17..9d9eb5648e 100644 --- a/id_table.h +++ b/id_table.h @@ -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 */ |