@@ -115,6 +115,24 @@ static cmark_node *make_str_with_entities(subject *subj,
115
115
}
116
116
}
117
117
118
+ // Like cmark_node_append_child but without costly sanity checks.
119
+ // Assumes that child was newly created.
120
+ static void append_child (cmark_node * node , cmark_node * child ) {
121
+ cmark_node * old_last_child = node -> last_child ;
122
+
123
+ child -> next = NULL ;
124
+ child -> prev = old_last_child ;
125
+ child -> parent = node ;
126
+ node -> last_child = child ;
127
+
128
+ if (old_last_child ) {
129
+ old_last_child -> next = child ;
130
+ } else {
131
+ // Also set first_child if node previously had no children.
132
+ node -> first_child = child ;
133
+ }
134
+ }
135
+
118
136
// Duplicate a chunk by creating a copy of the buffer not by reusing the
119
137
// buffer like cmark_chunk_dup does.
120
138
static cmark_chunk chunk_clone (cmark_mem * mem , cmark_chunk * src ) {
@@ -158,7 +176,7 @@ static CMARK_INLINE cmark_node *make_autolink(subject *subj,
158
176
link -> start_line = link -> end_line = subj -> line ;
159
177
link -> start_column = start_column + 1 ;
160
178
link -> end_column = end_column + 1 ;
161
- cmark_node_append_child (link , make_str_with_entities (subj , start_column + 1 , end_column - 1 , & url ));
179
+ append_child (link , make_str_with_entities (subj , start_column + 1 , end_column - 1 , & url ));
162
180
return link ;
163
181
}
164
182
@@ -777,7 +795,8 @@ static delimiter *S_insert_emph(subject *subj, delimiter *opener,
777
795
tmp = opener_inl -> next ;
778
796
while (tmp && tmp != closer_inl ) {
779
797
tmpnext = tmp -> next ;
780
- cmark_node_append_child (emph , tmp );
798
+ cmark_node_unlink (tmp );
799
+ append_child (emph , tmp );
781
800
tmp = tmpnext ;
782
801
}
783
802
cmark_node_insert_after (opener_inl , emph );
@@ -1299,7 +1318,8 @@ static cmark_node *handle_close_bracket(cmark_parser *parser, subject *subj) {
1299
1318
tmp = opener -> inl_text -> next ;
1300
1319
while (tmp ) {
1301
1320
tmpnext = tmp -> next ;
1302
- cmark_node_append_child (inl , tmp );
1321
+ cmark_node_unlink (tmp );
1322
+ append_child (inl , tmp );
1303
1323
tmp = tmpnext ;
1304
1324
}
1305
1325
@@ -1512,7 +1532,7 @@ static int parse_inline(cmark_parser *parser, subject *subj, cmark_node *parent,
1512
1532
new_inl = make_str (subj , startpos , endpos - 1 , contents );
1513
1533
}
1514
1534
if (new_inl != NULL ) {
1515
- cmark_node_append_child (parent , new_inl );
1535
+ append_child (parent , new_inl );
1516
1536
}
1517
1537
1518
1538
return 1 ;
0 commit comments