@@ -111,6 +111,24 @@ static cmark_node *make_str_with_entities(subject *subj,
111
111
}
112
112
}
113
113
114
+ // Like cmark_node_append_child but without costly sanity checks.
115
+ // Assumes that child was newly created.
116
+ static void append_child (cmark_node * node , cmark_node * child ) {
117
+ cmark_node * old_last_child = node -> last_child ;
118
+
119
+ child -> next = NULL ;
120
+ child -> prev = old_last_child ;
121
+ child -> parent = node ;
122
+ node -> last_child = child ;
123
+
124
+ if (old_last_child ) {
125
+ old_last_child -> next = child ;
126
+ } else {
127
+ // Also set first_child if node previously had no children.
128
+ node -> first_child = child ;
129
+ }
130
+ }
131
+
114
132
// Duplicate a chunk by creating a copy of the buffer not by reusing the
115
133
// buffer like cmark_chunk_dup does.
116
134
static cmark_chunk chunk_clone (cmark_mem * mem , cmark_chunk * src ) {
@@ -154,7 +172,7 @@ static CMARK_INLINE cmark_node *make_autolink(subject *subj,
154
172
link -> start_line = link -> end_line = subj -> line ;
155
173
link -> start_column = start_column + 1 ;
156
174
link -> end_column = end_column + 1 ;
157
- cmark_node_append_child (link , make_str_with_entities (subj , start_column + 1 , end_column - 1 , & url ));
175
+ append_child (link , make_str_with_entities (subj , start_column + 1 , end_column - 1 , & url ));
158
176
return link ;
159
177
}
160
178
@@ -768,7 +786,8 @@ static delimiter *S_insert_emph(subject *subj, delimiter *opener,
768
786
tmp = opener_inl -> next ;
769
787
while (tmp && tmp != closer_inl ) {
770
788
tmpnext = tmp -> next ;
771
- cmark_node_append_child (emph , tmp );
789
+ cmark_node_unlink (tmp );
790
+ append_child (emph , tmp );
772
791
tmp = tmpnext ;
773
792
}
774
793
cmark_node_insert_after (opener_inl , emph );
@@ -1238,7 +1257,8 @@ static cmark_node *handle_close_bracket(cmark_parser *parser, subject *subj) {
1238
1257
tmp = opener -> inl_text -> next ;
1239
1258
while (tmp ) {
1240
1259
tmpnext = tmp -> next ;
1241
- cmark_node_append_child (inl , tmp );
1260
+ cmark_node_unlink (tmp );
1261
+ append_child (inl , tmp );
1242
1262
tmp = tmpnext ;
1243
1263
}
1244
1264
@@ -1451,7 +1471,7 @@ static int parse_inline(cmark_parser *parser, subject *subj, cmark_node *parent,
1451
1471
new_inl = make_str (subj , startpos , endpos - 1 , contents );
1452
1472
}
1453
1473
if (new_inl != NULL ) {
1454
- cmark_node_append_child (parent , new_inl );
1474
+ append_child (parent , new_inl );
1455
1475
}
1456
1476
1457
1477
return 1 ;
0 commit comments