Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

st: st_foreach_nocheck

gc iterates over hashes much - method tables, constants tables, variables tables.
And its iteration methods always returns ST_CONTINUE and do not modify table size.
  • Loading branch information...
commit 3a672936016c4f15fe3e1b5ff90051e78f104810 1 parent 0b71e4c
@funny-falcon authored
Showing with 38 additions and 15 deletions.
  1. +10 −10 gc.c
  2. +1 −0  include/ruby/st.h
  3. +22 −0 st.c
  4. +4 −4 variable.c
  5. +1 −1  vm.c
View
20 gc.c
@@ -1604,7 +1604,7 @@ mark_tbl(rb_objspace_t *objspace, st_table *tbl, int lev)
if (!tbl || tbl->num_entries == 0) return;
arg.objspace = objspace;
arg.lev = lev;
- st_foreach(tbl, mark_entry, (st_data_t)&arg);
+ st_foreach_nocheck(tbl, mark_entry, (st_data_t)&arg);
}
static int
@@ -1622,7 +1622,7 @@ mark_set(rb_objspace_t *objspace, st_table *tbl, int lev)
if (!tbl) return;
arg.objspace = objspace;
arg.lev = lev;
- st_foreach(tbl, mark_key, (st_data_t)&arg);
+ st_foreach_nocheck(tbl, mark_key, (st_data_t)&arg);
}
void
@@ -1647,7 +1647,7 @@ mark_hash(rb_objspace_t *objspace, st_table *tbl, int lev)
if (!tbl) return;
arg.objspace = objspace;
arg.lev = lev;
- st_foreach(tbl, mark_keyvalue, (st_data_t)&arg);
+ st_foreach_nocheck(tbl, mark_keyvalue, (st_data_t)&arg);
}
void
@@ -1700,7 +1700,7 @@ mark_m_tbl(rb_objspace_t *objspace, st_table *tbl, int lev)
if (!tbl) return;
arg.objspace = objspace;
arg.lev = lev;
- st_foreach(tbl, mark_method_entry_i, (st_data_t)&arg);
+ st_foreach_nocheck(tbl, mark_method_entry_i, (st_data_t)&arg);
}
static int
@@ -1713,7 +1713,7 @@ free_method_entry_i(ID key, rb_method_entry_t *me, st_data_t data)
void
rb_free_m_table(st_table *tbl)
{
- st_foreach(tbl, free_method_entry_i, 0);
+ st_foreach_nocheck(tbl, free_method_entry_i, 0);
st_free_table(tbl);
}
@@ -1733,7 +1733,7 @@ mark_const_tbl(rb_objspace_t *objspace, st_table *tbl, int lev)
if (!tbl) return;
arg.objspace = objspace;
arg.lev = lev;
- st_foreach(tbl, mark_const_entry_i, (st_data_t)&arg);
+ st_foreach_nocheck(tbl, mark_const_entry_i, (st_data_t)&arg);
}
static int
@@ -1746,7 +1746,7 @@ free_const_entry_i(ID key, rb_const_entry_t *ce, st_data_t data)
void
rb_free_const_table(st_table *tbl)
{
- st_foreach(tbl, free_const_entry_i, 0);
+ st_foreach_nocheck(tbl, free_const_entry_i, 0);
st_free_table(tbl);
}
@@ -3205,13 +3205,13 @@ rb_objspace_call_finalizer(rb_objspace_t *objspace)
/* because mark will not be removed */
finalize_deferred(objspace);
mark_tbl(objspace, finalizer_table, 0);
- st_foreach(finalizer_table, chain_finalized_object,
+ st_foreach_nocheck(finalizer_table, chain_finalized_object,
(st_data_t)&deferred_final_list);
} while (deferred_final_list);
/* force to run finalizer */
while (finalizer_table->num_entries) {
struct force_finalize_list *list = 0;
- st_foreach(finalizer_table, force_chain_object, (st_data_t)&list);
+ st_foreach_nocheck(finalizer_table, force_chain_object, (st_data_t)&list);
while (list) {
struct force_finalize_list *curr = list;
st_data_t obj = (st_data_t)curr->obj;
@@ -3492,7 +3492,7 @@ count_objects(int argc, VALUE *argv, VALUE os)
hash = rb_hash_new();
}
else if (!RHASH_EMPTY_P(hash)) {
- st_foreach(RHASH_TBL(hash), set_zero, hash);
+ st_foreach_nocheck(RHASH_TBL(hash), set_zero, hash);
}
rb_hash_aset(hash, ID2SYM(rb_intern("TOTAL")), SIZET2NUM(total));
rb_hash_aset(hash, ID2SYM(rb_intern("FREE")), SIZET2NUM(freed));
View
1  include/ruby/st.h
@@ -126,6 +126,7 @@ int st_lookup(st_table *, st_data_t, st_data_t *);
int st_get_key(st_table *, st_data_t, st_data_t *);
int st_update(st_table *table, st_data_t key, int (*func)(st_data_t key, st_data_t *value, st_data_t arg), st_data_t arg);
int st_foreach(st_table *, int (*)(ANYARGS), st_data_t);
+int st_foreach_nocheck(st_table *, int (*)(ANYARGS), st_data_t);
int st_reverse_foreach(st_table *, int (*)(ANYARGS), st_data_t);
void st_add_direct(st_table *, st_data_t, st_data_t);
void st_free_table(st_table *);
View
22 st.c
@@ -1012,6 +1012,28 @@ st_update(st_table *table, st_data_t key, int (*func)(st_data_t key, st_data_t *
}
int
+st_foreach_nocheck(st_table *table, int (*func)(ANYARGS), st_data_t arg)
+{
+ if (table->num_entries == 0) return 0;
+ if (ULTRA_PACKED(table)) {
+ (*func)(UPKEY(table), UPVAL(table), arg);
+ }
+ else if (table->entries_packed) {
+ register st_index_t i;
+ for(i = 0; i < table->num_entries; i++) {
+ (*func)(PKEY(table, i), PVAL(table, i), arg);
+ }
+ }
+ else {
+ st_table_entry *ptr;
+ for(ptr = table->head; ptr; ptr = ptr->fore) {
+ (*func)(ptr->key, ptr->record, arg);
+ }
+ }
+ return 0;
+}
+
+int
st_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg)
{
st_table_entry *ptr, **last, *tmp;
View
8 variable.c
@@ -473,7 +473,7 @@ void
rb_gc_mark_global_tbl(void)
{
if (rb_global_tbl)
- st_foreach_safe(rb_global_tbl, mark_global_entry, 0);
+ st_foreach_nocheck(rb_global_tbl, mark_global_entry, 0);
}
static ID
@@ -768,7 +768,7 @@ rb_f_global_variables(void)
char buf[2];
int i;
- st_foreach_safe(rb_global_tbl, gvar_i, ary);
+ st_foreach_nocheck(rb_global_tbl, gvar_i, ary);
buf[0] = '$';
for (i = 1; i <= 9; ++i) {
buf[1] = (char)(i + '0');
@@ -926,7 +926,7 @@ static int
givar_i(VALUE obj, st_table *tbl)
{
if (rb_special_const_p(obj)) {
- st_foreach_safe(tbl, givar_mark_i, 0);
+ st_foreach_nocheck(tbl, givar_mark_i, 0);
}
return ST_CONTINUE;
}
@@ -936,7 +936,7 @@ rb_mark_generic_ivar_tbl(void)
{
if (!generic_iv_tbl) return;
if (special_generic_ivar == 0) return;
- st_foreach_safe(generic_iv_tbl, givar_i, 0);
+ st_foreach_nocheck(generic_iv_tbl, givar_i, 0);
}
void
View
2  vm.c
@@ -1572,7 +1572,7 @@ rb_vm_mark(void *ptr)
if (ptr) {
rb_vm_t *vm = ptr;
if (vm->living_threads) {
- st_foreach(vm->living_threads, vm_mark_each_thread_func, 0);
+ st_foreach_nocheck(vm->living_threads, vm_mark_each_thread_func, 0);
}
RUBY_MARK_UNLESS_NULL(vm->thgroup_default);
RUBY_MARK_UNLESS_NULL(vm->mark_object_ary);

0 comments on commit 3a67293

Please sign in to comment.
Something went wrong with that request. Please try again.