Remove more recursion.

This commit is contained in:
Jim Derry 2021-07-30 17:15:58 -04:00
parent c21deae8c0
commit a34b0f07b5
2 changed files with 42 additions and 10 deletions

View file

@ -1629,6 +1629,7 @@ void TY_(BQ2Div)( TidyDocImpl* doc, Node *node )
node = next ? next : TY_(pop)(stack); node = next ? next : TY_(pop)(stack);
} }
TY_(freeStack)(stack);
} }
@ -2591,6 +2592,7 @@ void TY_(ConvertCDATANodes)(TidyDocImpl* doc, Node* node)
*/ */
void TY_(FixLanguageInformation)(TidyDocImpl* doc, Node* node, Bool wantXmlLang, Bool wantLang) void TY_(FixLanguageInformation)(TidyDocImpl* doc, Node* node, Bool wantXmlLang, Bool wantLang)
{ {
Stack *stack = TY_(newStack)(doc, 16);
Node* next; Node* next;
while (node) while (node)
@ -2634,10 +2636,15 @@ void TY_(FixLanguageInformation)(TidyDocImpl* doc, Node* node, Bool wantXmlLang,
} }
if (node->content) if (node->content)
TY_(FixLanguageInformation)(doc, node->content, wantXmlLang, wantLang); {
TY_(push)(stack, next);
node = next; node = node->content;
continue;
} }
node = next ? next : TY_(pop)(stack);
}
TY_(freeStack)(stack);
} }
/* /*
@ -2669,6 +2676,7 @@ void TY_(FixXhtmlNamespace)(TidyDocImpl* doc, Bool wantXmlns)
*/ */
void TY_(FixAnchors)(TidyDocImpl* doc, Node *node, Bool wantName, Bool wantId) void TY_(FixAnchors)(TidyDocImpl* doc, Node *node, Bool wantName, Bool wantId)
{ {
Stack *stack = TY_(newStack)(doc, 16);
Node* next; Node* next;
while (node) while (node)
@ -2738,10 +2746,15 @@ void TY_(FixAnchors)(TidyDocImpl* doc, Node *node, Bool wantName, Bool wantId)
} }
if (node->content) if (node->content)
TY_(FixAnchors)(doc, node->content, wantName, wantId); {
TY_(push)(stack, next);
node = next; node = node->content;
continue;
} }
node = next ? next : TY_(pop)(stack);
}
TY_(freeStack)(stack);
} }
/* Issue #567 - move style elements from body to head /* Issue #567 - move style elements from body to head
@ -2785,6 +2798,7 @@ static void StyleToHead(TidyDocImpl* doc, Node *head, Node *node, Bool fix, int
indent--; indent--;
} }
} }
TY_(freeStack)(stack);
} }

View file

@ -1630,15 +1630,19 @@ static Bool nodeHasAlignAttr( Node *node )
*/ */
static void TY_(CheckHTML5)( TidyDocImpl* doc, Node* node ) static void TY_(CheckHTML5)( TidyDocImpl* doc, Node* node )
{ {
Stack *stack = TY_(newStack)(doc, 16);
Bool clean = cfgBool( doc, TidyMakeClean ); Bool clean = cfgBool( doc, TidyMakeClean );
Bool already_strict = cfgBool( doc, TidyStrictTagsAttr ); Bool already_strict = cfgBool( doc, TidyStrictTagsAttr );
Node* body = TY_(FindBody)( doc ); Node* body = TY_(FindBody)( doc );
Node* next;
Bool warn = yes; /* should this be a warning, error, or report??? */ Bool warn = yes; /* should this be a warning, error, or report??? */
AttVal* attr = NULL; AttVal* attr = NULL;
int i = 0; int i = 0;
while (node) while (node)
{ {
next = node->next;
if ( nodeHasAlignAttr( node ) ) { if ( nodeHasAlignAttr( node ) ) {
/* @todo: Is this for ALL elements that accept an 'align' attribute, /* @todo: Is this for ALL elements that accept an 'align' attribute,
* or should this be a sub-set test? * or should this be a sub-set test?
@ -1792,10 +1796,15 @@ static void TY_(CheckHTML5)( TidyDocImpl* doc, Node* node )
} }
if (node->content) if (node->content)
TY_(CheckHTML5)( doc, node->content ); {
TY_(push)(stack, next);
node = node->next; node = node->content;
continue;
} }
node = next ? next : TY_(pop)(stack);
}
TY_(freeStack)(stack);
} }
/***************************************************************************** /*****************************************************************************
* END HTML5 STUFF * END HTML5 STUFF
@ -1816,6 +1825,8 @@ static void TY_(CheckHTML5)( TidyDocImpl* doc, Node* node )
*/ */
static void TY_(CheckHTMLTagsAttribsVersions)( TidyDocImpl* doc, Node* node ) static void TY_(CheckHTMLTagsAttribsVersions)( TidyDocImpl* doc, Node* node )
{ {
Stack *stack = TY_(newStack)(doc, 16);
Node *next;
uint versionEmitted = doc->lexer->versionEmitted; uint versionEmitted = doc->lexer->versionEmitted;
uint declared = doc->lexer->doctype; uint declared = doc->lexer->doctype;
uint version = versionEmitted == 0 ? declared : versionEmitted; uint version = versionEmitted == 0 ? declared : versionEmitted;
@ -1830,6 +1841,8 @@ static void TY_(CheckHTMLTagsAttribsVersions)( TidyDocImpl* doc, Node* node )
while (node) while (node)
{ {
next = node->next;
/* This bit here handles our HTML tags */ /* This bit here handles our HTML tags */
if ( TY_(nodeIsElement)(node) && node->tag ) { if ( TY_(nodeIsElement)(node) && node->tag ) {
@ -1914,10 +1927,15 @@ static void TY_(CheckHTMLTagsAttribsVersions)( TidyDocImpl* doc, Node* node )
} }
if (node->content) if (node->content)
TY_(CheckHTMLTagsAttribsVersions)( doc, node->content ); {
TY_(push)(stack, next);
node = node->next; node = node->content;
continue;
} }
node = next ? next : TY_(pop)(stack);
}
TY_(freeStack)(stack);
} }