Refactor fast_checker_counter to be a threaded counter, not a global

svn: r11596
This commit is contained in:
Kevin Tew 2008-09-09 15:53:19 +00:00
parent 81b486ef1f
commit 95ab952eb9

View File

@ -529,9 +529,7 @@ START_XFORM_SKIP;
version takes to long, we back out to the general case. (We don't version takes to long, we back out to the general case. (We don't
even check for stack overflow, so keep the max limit low.) */ even check for stack overflow, so keep the max limit low.) */
static int fast_checker_counter; static int check_cycles_fast(Scheme_Object *obj, PrintParams *pp, int *fast_checker_counter)
static int check_cycles_fast(Scheme_Object *obj, PrintParams *pp)
{ {
Scheme_Type t; Scheme_Type t;
int cycle = 0; int cycle = 0;
@ -540,18 +538,18 @@ static int check_cycles_fast(Scheme_Object *obj, PrintParams *pp)
if (t < 0) if (t < 0)
return 1; return 1;
if (fast_checker_counter-- < 0) if ((*fast_checker_counter)-- < 0)
return -1; return -1;
if (SCHEME_PAIRP(obj) || SCHEME_MUTABLE_PAIRP(obj)) { if (SCHEME_PAIRP(obj) || SCHEME_MUTABLE_PAIRP(obj)) {
obj->type = -t; obj->type = -t;
cycle = check_cycles_fast(SCHEME_CAR(obj), pp); cycle = check_cycles_fast(SCHEME_CAR(obj), pp, fast_checker_counter);
if (!cycle) if (!cycle)
cycle = check_cycles_fast(SCHEME_CDR(obj), pp); cycle = check_cycles_fast(SCHEME_CDR(obj), pp, fast_checker_counter);
obj->type = t; obj->type = t;
} else if (pp->print_box && SCHEME_BOXP(obj)) { } else if (pp->print_box && SCHEME_BOXP(obj)) {
obj->type = -t; obj->type = -t;
cycle = check_cycles_fast(SCHEME_BOX_VAL(obj), pp); cycle = check_cycles_fast(SCHEME_BOX_VAL(obj), pp, fast_checker_counter);
obj->type = t; obj->type = t;
} else if (SCHEME_VECTORP(obj)) { } else if (SCHEME_VECTORP(obj)) {
int i, len; int i, len;
@ -559,7 +557,7 @@ static int check_cycles_fast(Scheme_Object *obj, PrintParams *pp)
obj->type = -t; obj->type = -t;
len = SCHEME_VEC_SIZE(obj); len = SCHEME_VEC_SIZE(obj);
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
cycle = check_cycles_fast(SCHEME_VEC_ELS(obj)[i], pp); cycle = check_cycles_fast(SCHEME_VEC_ELS(obj)[i], pp, fast_checker_counter);
if (cycle) if (cycle)
break; break;
} }
@ -578,7 +576,7 @@ static int check_cycles_fast(Scheme_Object *obj, PrintParams *pp)
obj->type = -t; obj->type = -t;
while (i--) { while (i--) {
if (scheme_inspector_sees_part(obj, pp->inspector, i)) { if (scheme_inspector_sees_part(obj, pp->inspector, i)) {
cycle = check_cycles_fast(((Scheme_Structure *)obj)->slots[i], pp); cycle = check_cycles_fast(((Scheme_Structure *)obj)->slots[i], pp, fast_checker_counter);
if (cycle) if (cycle)
break; break;
} }
@ -840,8 +838,8 @@ print_to_string(Scheme_Object *obj,
if (params.print_graph) if (params.print_graph)
cycles = 1; cycles = 1;
else { else {
fast_checker_counter = 50; int fast_checker_counter = 50;
cycles = check_cycles_fast(obj, (PrintParams *)&params); cycles = check_cycles_fast(obj, (PrintParams *)&params, &fast_checker_counter);
if (cycles == -1) { if (cycles == -1) {
ht = scheme_make_hash_table(SCHEME_hash_ptr); ht = scheme_make_hash_table(SCHEME_hash_ptr);
cycles = check_cycles(obj, ht, (PrintParams *)&params); cycles = check_cycles(obj, ht, (PrintParams *)&params);