Skip to content

Commit 0656bf9

Browse files
Revert "Early-terminate the loop in check_open_blocks when the current line is blank."
This reverts commit aa73711.
1 parent 7f567e2 commit 0656bf9

File tree

2 files changed

+3
-39
lines changed

2 files changed

+3
-39
lines changed

src/blocks.c

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -409,11 +409,9 @@ static cmark_node *finalize(cmark_parser *parser, cmark_node *b) {
409409
// in parser. (Used to check that the counts in parser, which are updated incrementally, are
410410
// correct.)
411411
bool check_open_block_counts(cmark_parser *parser) {
412-
cmark_parser tmp_parser = {0}; // Only used for its open_block_counts and total_open_blocks fields.
412+
cmark_parser tmp_parser = {0}; // Only used for its open_block_counts field.
413413
add_open_block_counts(&tmp_parser, parser->root);
414-
return
415-
tmp_parser.total_open_blocks == parser->total_open_blocks &&
416-
memcmp(tmp_parser.open_block_counts, parser->open_block_counts, sizeof(parser->open_block_counts)) == 0;
414+
return memcmp(tmp_parser.open_block_counts, parser->open_block_counts, sizeof(parser->open_block_counts)) == 0;
417415
}
418416

419417
// Add a node as child of another. Return pointer to child.
@@ -1084,14 +1082,10 @@ static cmark_node *check_open_blocks(cmark_parser *parser, cmark_chunk *input,
10841082
*all_matched = false;
10851083
cmark_node *container = parser->root;
10861084
cmark_node_type cont_type;
1087-
cmark_parser tmp_parser; // Only used for its open_block_counts and total_open_blocks fields.
1088-
memcpy(tmp_parser.open_block_counts, parser->open_block_counts, sizeof(parser->open_block_counts));
1089-
tmp_parser.total_open_blocks = parser->total_open_blocks;
10901085

10911086
assert(check_open_block_counts(parser));
10921087

10931088
while (S_last_child_is_open(container)) {
1094-
decr_open_block_count(&tmp_parser, S_type(container));
10951089
container = container->last_child;
10961090
cont_type = S_type(container);
10971091

@@ -1103,26 +1097,6 @@ static cmark_node *check_open_blocks(cmark_parser *parser, cmark_chunk *input,
11031097
continue;
11041098
}
11051099

1106-
if (parser->blank) {
1107-
const size_t n_list = read_open_block_count(&tmp_parser, CMARK_NODE_LIST);
1108-
const size_t n_item = read_open_block_count(&tmp_parser, CMARK_NODE_ITEM);
1109-
const size_t n_para = read_open_block_count(&tmp_parser, CMARK_NODE_PARAGRAPH);
1110-
if (n_list + n_item + n_para == tmp_parser.total_open_blocks) {
1111-
if (parser->current->flags & CMARK_NODE__OPEN_BLOCK) {
1112-
if (S_type(parser->current) == CMARK_NODE_PARAGRAPH) {
1113-
container = parser->current;
1114-
goto done;
1115-
}
1116-
if (S_type(parser->current) == CMARK_NODE_ITEM) {
1117-
if (parser->current->flags & CMARK_NODE__OPEN) {
1118-
container = parser->current;
1119-
cont_type = S_type(container);
1120-
}
1121-
}
1122-
}
1123-
}
1124-
}
1125-
11261100
switch (cont_type) {
11271101
case CMARK_NODE_BLOCK_QUOTE:
11281102
if (!parse_block_quote_prefix(parser, input))
@@ -1413,7 +1387,7 @@ static void add_text_to_container(cmark_parser *parser, cmark_node *container,
14131387
S_set_last_line_blank(container, last_line_blank);
14141388

14151389
tmp = container;
1416-
while (tmp->parent && S_last_line_blank(tmp->parent)) {
1390+
while (tmp->parent) {
14171391
S_set_last_line_blank(tmp->parent, false);
14181392
tmp = tmp->parent;
14191393
}

src/parser.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,29 +66,19 @@ struct cmark_parser {
6666
* For example, CMARK_NODE_LIST (0x8003) is stored at offset 2.
6767
*/
6868
size_t open_block_counts[CMARK_NODE_TYPE_BLOCK_LIMIT];
69-
size_t total_open_blocks;
7069
};
7170

7271
static CMARK_INLINE void incr_open_block_count(cmark_parser *parser, cmark_node_type type) {
7372
assert(type > CMARK_NODE_TYPE_BLOCK);
7473
assert(type <= CMARK_NODE_TYPE_BLOCK + CMARK_NODE_TYPE_BLOCK_LIMIT);
7574
parser->open_block_counts[type - CMARK_NODE_TYPE_BLOCK - 1]++;
76-
parser->total_open_blocks++;
7775
}
7876

7977
static CMARK_INLINE void decr_open_block_count(cmark_parser *parser, cmark_node_type type) {
8078
assert(type > CMARK_NODE_TYPE_BLOCK);
8179
assert(type <= CMARK_NODE_TYPE_BLOCK + CMARK_NODE_TYPE_BLOCK_LIMIT);
8280
assert(parser->open_block_counts[type - CMARK_NODE_TYPE_BLOCK - 1] > 0);
8381
parser->open_block_counts[type - CMARK_NODE_TYPE_BLOCK - 1]--;
84-
assert(parser->total_open_blocks > 0);
85-
parser->total_open_blocks--;
86-
}
87-
88-
static CMARK_INLINE size_t read_open_block_count(cmark_parser *parser, cmark_node_type type) {
89-
assert(type > CMARK_NODE_TYPE_BLOCK);
90-
assert(type <= CMARK_NODE_TYPE_BLOCK + CMARK_NODE_TYPE_BLOCK_LIMIT);
91-
return parser->open_block_counts[type - CMARK_NODE_TYPE_BLOCK - 1];
9282
}
9383

9484
#ifdef __cplusplus

0 commit comments

Comments
 (0)