From dd9eaf09d344a4b18b2750cef08795a097891c08 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Thu, 25 Oct 2001 19:08:52 +0000 Subject: Eliminate completely gratuitous tail recursion in three functions [originally from svn r1328] --- bk_xhtml.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/bk_xhtml.c b/bk_xhtml.c index e4a25bf..ebd19a3 100644 --- a/bk_xhtml.c +++ b/bk_xhtml.c @@ -815,11 +815,11 @@ static int xhtml_do_naked_contents(FILE *fp, xhtmlfile *file) static int xhtml_do_contents_limit(FILE *fp, xhtmlfile *file, int limit) { int count = 0; - if (!file) - return 0; - count += xhtml_do_contents_section_limit(fp, file->sections, limit); - count += xhtml_do_contents_limit(fp, file->child, limit); - count += xhtml_do_contents_limit(fp, file->next, limit); + while (file) { + count += xhtml_do_contents_section_limit(fp, file->sections, limit); + count += xhtml_do_contents_limit(fp, file->child, limit); + file = file->next; + } return count; } @@ -830,14 +830,14 @@ static int xhtml_do_contents_limit(FILE *fp, xhtmlfile *file, int limit) static int xhtml_do_contents_section_deep_limit(FILE *fp, xhtmlsection *section, int limit) { int count = 0; - if (!section) - return 0; - if (!xhtml_add_contents_entry(fp, section, limit)) - return 0; - else - count = 1; - count += xhtml_do_contents_section_deep_limit(fp, section->child, limit); - count += xhtml_do_contents_section_deep_limit(fp, section->next, limit); + while (section) { + if (!xhtml_add_contents_entry(fp, section, limit)) + return 0; + else + count++; + count += xhtml_do_contents_section_deep_limit(fp, section->child, limit); + section = section->next; + } return count; } @@ -894,12 +894,12 @@ static int xhtml_add_contents_entry(FILE *fp, xhtmlsection *section, int limit) */ static void xhtml_do_sections(FILE *fp, xhtmlsection *sections) { - if (!sections) - return; - currentsection = sections; - xhtml_do_paras(fp, sections->para); - xhtml_do_sections(fp, sections->child); - xhtml_do_sections(fp, sections->next); + while (sections) { + currentsection = sections; + xhtml_do_paras(fp, sections->para); + xhtml_do_sections(fp, sections->child); + sections = sections->next; + } } /* Write this list of paragraphs. Close off all lists at the end. */ -- cgit v1.1