From: Fletcher T. Penney Date: Tue, 28 Mar 2017 22:58:10 +0000 (-0400) Subject: CHANGED: Refactor code slightly X-Git-Tag: 6.0.3^2~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=478a067ff4909f9b3e3de2065f816471f417be4f;p=multimarkdown CHANGED: Refactor code slightly --- diff --git a/Sources/libMultiMarkdown/mmd.c b/Sources/libMultiMarkdown/mmd.c index 55d1242..cef81be 100644 --- a/Sources/libMultiMarkdown/mmd.c +++ b/Sources/libMultiMarkdown/mmd.c @@ -1009,7 +1009,7 @@ void mmd_pair_tokens_in_block(token * block, token_pair_engine * e, stack * s) { /// open a pair. This allows for complex behavior without having to bog down the tokenizer /// with figuring out which type of asterisk we have. Default behavior is that open and close /// are enabled, so we just have to figure out when to turn it off. -void mmd_assign_ambidextrous_tokens_in_block(mmd_engine * e, token * block, const char * str, size_t start_offset) { +void mmd_assign_ambidextrous_tokens_in_block(mmd_engine * e, token * block, size_t start_offset) { if (block == NULL || block->child == NULL) return; @@ -1018,6 +1018,8 @@ void mmd_assign_ambidextrous_tokens_in_block(mmd_engine * e, token * block, cons token * t = block->child; + char * str = e->dstr->str; + while (t != NULL) { switch (t->type) { case BLOCK_META: @@ -1050,7 +1052,7 @@ void mmd_assign_ambidextrous_tokens_in_block(mmd_engine * e, token * block, cons case BLOCK_TABLE: case BLOCK_TERM: // Assign child tokens of blocks - mmd_assign_ambidextrous_tokens_in_block(e, t, str, start_offset); + mmd_assign_ambidextrous_tokens_in_block(e, t, start_offset); break; case CRITIC_SUB_DIV: // Divide this into two tokens @@ -1834,6 +1836,11 @@ void strip_line_tokens_from_block(mmd_engine * e, token * block) { /// Parse part of the string into a token tree token * mmd_engine_parse_substring(mmd_engine * e, size_t byte_start, size_t byte_len) { + // Free existing parse tree + if (e->root) + token_tree_free(e->root); + + // New parse tree // Reset definition stack e->definition_stack->size = 0; @@ -1846,7 +1853,7 @@ token * mmd_engine_parse_substring(mmd_engine * e, size_t byte_start, size_t byt if (doc) { // Parse blocks for pairs - mmd_assign_ambidextrous_tokens_in_block(e, doc, e->dstr->str, 0); + mmd_assign_ambidextrous_tokens_in_block(e, doc, 0); // Prepare stack to be used for token pairing // This avoids allocating/freeing one for each iteration. @@ -1873,11 +1880,6 @@ token * mmd_engine_parse_substring(mmd_engine * e, size_t byte_start, size_t byt /// Parse the entire string into a token tree void mmd_engine_parse_string(mmd_engine * e) { - // Free existing parse tree - if (e->root) - token_tree_free(e->root); - - // New parse tree e->root = mmd_engine_parse_substring(e, 0, e->dstr->currentStringLength); }