Skip to content

Commit

Permalink
Fix quadratic behavior with smart quotes
Browse files Browse the repository at this point in the history
Make sure to remove matching smart quote delimiters. Otherwise, the
same opener could be found over and over again, preventing the
`openers_bottom` optimization from kicking in and leading to quadratic
behavior when processing lots of quotes.

Fixes #388.
  • Loading branch information
nwellnhof authored and jgm committed Jul 16, 2021
1 parent 023d887 commit 10b56dc
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/inlines.c
Original file line number Diff line number Diff line change
Expand Up @@ -698,18 +698,22 @@ static void process_emphasis(subject *subj, delimiter *stack_bottom) {
} else {
closer = closer->next;
}
} else if (closer->delim_char == '\'') {
cmark_node_set_literal(closer->inl_text, RIGHTSINGLEQUOTE);
if (opener_found) {
cmark_node_set_literal(opener->inl_text, LEFTSINGLEQUOTE);
} else if (closer->delim_char == '\'' || closer->delim_char == '"') {
if (closer->delim_char == '\'') {
cmark_node_set_literal(closer->inl_text, RIGHTSINGLEQUOTE);
} else {
cmark_node_set_literal(closer->inl_text, RIGHTDOUBLEQUOTE);
}
closer = closer->next;
} else if (closer->delim_char == '"') {
cmark_node_set_literal(closer->inl_text, RIGHTDOUBLEQUOTE);
if (opener_found) {
cmark_node_set_literal(opener->inl_text, LEFTDOUBLEQUOTE);
if (old_closer->delim_char == '\'') {
cmark_node_set_literal(opener->inl_text, LEFTSINGLEQUOTE);
} else {
cmark_node_set_literal(opener->inl_text, LEFTDOUBLEQUOTE);
}
remove_delimiter(subj, opener);
remove_delimiter(subj, old_closer);
}
closer = closer->next;
}
if (!opener_found) {
// set lower bound for future searches for openers
Expand Down

0 comments on commit 10b56dc

Please sign in to comment.