diff options
author | Robin Watts <robin.watts@artifex.com> | 2012-03-19 19:39:41 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2012-03-19 19:39:41 +0000 |
commit | 79c112d2e143c0433eb6a5014553e042e5d53029 (patch) | |
tree | 7e0a4553760a56fd80634f6cec863d74e8f9980c /apps/mupdfclean.c | |
parent | 40ae12884335856f803dc76bfbe97b1c8743b9b9 (diff) | |
download | mupdf-79c112d2e143c0433eb6a5014553e042e5d53029.tar.xz |
mupdfclean: eliminate mutual recursion (sweepobj/sweepref).
Mutual recursion was blowing the stack. This will still blow the
stack, but less often.
Diffstat (limited to 'apps/mupdfclean.c')
-rw-r--r-- | apps/mupdfclean.c | 50 |
1 files changed, 24 insertions, 26 deletions
diff --git a/apps/mupdfclean.c b/apps/mupdfclean.c index caee8d5b..2b652d99 100644 --- a/apps/mupdfclean.c +++ b/apps/mupdfclean.c @@ -53,31 +53,7 @@ static void usage(void) * Garbage collect objects not reachable from the trailer. */ -static void sweepref(pdf_obj *ref); - -static void sweepobj(pdf_obj *obj) -{ - int i; - - if (pdf_is_indirect(obj)) - sweepref(obj); - - else if (pdf_is_dict(obj)) - { - int n = pdf_dict_len(obj); - for (i = 0; i < n; i++) - sweepobj(pdf_dict_get_val(obj, i)); - } - - else if (pdf_is_array(obj)) - { - int n = pdf_array_len(obj); - for (i = 0; i < n; i++) - sweepobj(pdf_array_get(obj, i)); - } -} - -static void sweepref(pdf_obj *obj) +static pdf_obj *sweepref(pdf_obj *obj) { int num = pdf_to_num(obj); int gen = pdf_to_gen(obj); @@ -108,7 +84,29 @@ static void sweepref(pdf_obj *obj) /* Leave broken */ } - sweepobj(pdf_resolve_indirect(obj)); + return pdf_resolve_indirect(obj); +} + +static void sweepobj(pdf_obj *obj) +{ + int i; + + if (pdf_is_indirect(obj)) + obj = sweepref(obj); + + if (pdf_is_dict(obj)) + { + int n = pdf_dict_len(obj); + for (i = 0; i < n; i++) + sweepobj(pdf_dict_get_val(obj, i)); + } + + else if (pdf_is_array(obj)) + { + int n = pdf_array_len(obj); + for (i = 0; i < n; i++) + sweepobj(pdf_array_get(obj, i)); + } } /* |