summaryrefslogtreecommitdiff
path: root/id_table.c
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2022-01-25 16:11:24 -0500
committerPeter Zhu <peter@peterzhu.ca>2022-01-25 16:51:16 -0500
commit4d9ad91a35b16afde38fd4ae513a49d22e27b3ea (patch)
treed3c57dcaf33ea2310ca8e6195a739a0342c16cd1 /id_table.c
parent6e901939c67d7c1275c183b0bde4d5d1c78ef081 (diff)
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.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/5486
Diffstat (limited to 'id_table.c')
-rw-r--r--id_table.c42
1 files changed, 21 insertions, 21 deletions
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;
+ }
+ }
+}
+