diff options
author | Nick Wellnhofer <wellnhofer@aevum.de> | 2014-11-29 19:00:53 +0100 |
---|---|---|
committer | Nick Wellnhofer <wellnhofer@aevum.de> | 2014-11-29 21:49:14 +0100 |
commit | 664adf32706274333fe1053dc01853b117c31bce (patch) | |
tree | e55e70dcb9e887913f086688e9605b7af05b0376 /src/inlines.c | |
parent | a05151f75aa93a16b39333ba3d30e31930d61dec (diff) |
Optimize emph insertion
Avoid unnecessary malloc/free if opener is removed.
Diffstat (limited to 'src/inlines.c')
-rw-r--r-- | src/inlines.c | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/inlines.c b/src/inlines.c index 8487bf8..2652342 100644 --- a/src/inlines.c +++ b/src/inlines.c @@ -430,26 +430,26 @@ S_insert_emph(subject *subj, delimiter_stack *opener, delimiter_stack *closer) tempstack = nextstack; } - // create new emph or strong, and splice it in to our inlines - // between the opener and closer - emph = use_delims == 1 ? make_emph(inl->next) : make_strong(inl->next); - emph->next = closer->first_inline; - emph->prev = inl; - emph->parent = inl->parent; - inl->next = emph; - // if opener has 0 delims, remove it and its associated inline if (opener->delim_count == 0) { // replace empty opener inline with emph chunk_free(&(inl->as.literal)); - inl->type = emph->type; - inl->next = emph->next; - inl->first_child = emph->first_child; - free(emph); emph = inl; + emph->type = use_delims == 1 ? NODE_EMPH : NODE_STRONG; + emph->first_child = inl->next; // remove opener from stack remove_delimiter(subj, opener); } + else { + // create new emph or strong, and splice it in to our inlines + // between the opener and closer + emph = use_delims == 1 ? make_emph(inl->next) : make_strong(inl->next); + emph->parent = inl->parent; + emph->prev = inl; + inl->next = emph; + } + + emph->next = closer->first_inline; // fix tree structure tmp = emph->first_child; |