summaryrefslogtreecommitdiff
path: root/st.c
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-04-17 03:17:25 (GMT)
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-04-17 03:17:25 (GMT)
commit3c55b643aec09bbe779dab25b2397947eded2b9b (patch)
treed7705428a035cd7c4384a0e34d59415bf3de9ca4 /st.c
parentfcd679ed11e3e801431f2f931dbe925edb8df0bf (diff)
Adding `GC.compact` and compacting GC support.
This commit adds the new method `GC.compact` and compacting GC support. Please see this issue for caveats: https://bugs.ruby-lang.org/issues/15626 [Feature #15626] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67576 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'st.c')
-rw-r--r--st.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/st.c b/st.c
index ed235c6..cecc2ac 100644
--- a/st.c
+++ b/st.c
@@ -1548,7 +1548,7 @@ st_update(st_table *tab, st_data_t key,
different for ST_CHECK and when the current element is removed
during traversing. */
static inline int
-st_general_foreach(st_table *tab, int (*func)(ANYARGS), st_data_t arg,
+st_general_foreach(st_table *tab, int (*func)(ANYARGS), st_update_callback_func *replace, st_data_t arg,
int check_p)
{
st_index_t bin;
@@ -1572,6 +1572,15 @@ st_general_foreach(st_table *tab, int (*func)(ANYARGS), st_data_t arg,
rebuilds_num = tab->rebuilds_num;
hash = curr_entry_ptr->hash;
retval = (*func)(key, curr_entry_ptr->record, arg, 0);
+
+ if (retval == ST_REPLACE && replace) {
+ st_data_t value;
+ value = curr_entry_ptr->record;
+ retval = (*replace)(&key, &value, arg, TRUE);
+ curr_entry_ptr->key = key;
+ curr_entry_ptr->record = value;
+ }
+
if (rebuilds_num != tab->rebuilds_num) {
retry:
entries = tab->entries;
@@ -1600,6 +1609,8 @@ st_general_foreach(st_table *tab, int (*func)(ANYARGS), st_data_t arg,
curr_entry_ptr = &entries[i];
}
switch (retval) {
+ case ST_REPLACE:
+ break;
case ST_CONTINUE:
break;
case ST_CHECK:
@@ -1648,9 +1659,15 @@ st_general_foreach(st_table *tab, int (*func)(ANYARGS), st_data_t arg,
}
int
+st_foreach_with_replace(st_table *tab, int (*func)(ANYARGS), st_update_callback_func *replace, st_data_t arg)
+{
+ return st_general_foreach(tab, func, replace, arg, TRUE);
+}
+
+int
st_foreach(st_table *tab, int (*func)(ANYARGS), st_data_t arg)
{
- return st_general_foreach(tab, func, arg, FALSE);
+ return st_general_foreach(tab, func, NULL, arg, FALSE);
}
/* See comments for function st_delete_safe. */
@@ -1658,7 +1675,7 @@ int
st_foreach_check(st_table *tab, int (*func)(ANYARGS), st_data_t arg,
st_data_t never ATTRIBUTE_UNUSED)
{
- return st_general_foreach(tab, func, arg, TRUE);
+ return st_general_foreach(tab, func, NULL, arg, TRUE);
}
/* Set up array KEYS by at most SIZE keys of head table TAB entries.