Skip to content

Commit cec3765

Browse files
Yuki IzumiYuki Izumi
authored andcommitted
More runs in benchmark; .gitignore update
1 parent 4b83812 commit cec3765

File tree

3 files changed

+50
-49
lines changed

3 files changed

+50
-49
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,9 @@ bstrlib.txt
3232
build
3333
cmark.dSYM/*
3434
cmark
35+
36+
# Testing and benchmark
37+
alltests.md
38+
progit/
39+
bench/benchinput.md
40+
test/afl_results/

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ BENCHDIR=bench
1212
BENCHSAMPLES=$(wildcard $(BENCHDIR)/samples/*.md)
1313
BENCHFILE=$(BENCHDIR)/benchinput.md
1414
ALLTESTS=alltests.md
15-
NUMRUNS?=10
15+
NUMRUNS?=20
1616
CMARK=$(BUILDDIR)/src/cmark
1717
CMARK_FUZZ=$(BUILDDIR)/src/cmark-fuzz
1818
PROG?=$(CMARK)

src/inlines.c

Lines changed: 43 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -515,9 +515,17 @@ static void process_emphasis(subject *subj, delimiter *stack_bottom) {
515515
delimiter *opener;
516516
delimiter *old_closer;
517517
bool opener_found;
518-
int openers_bottom_index;
519-
delimiter *openers_bottom[6] = {stack_bottom, stack_bottom, stack_bottom,
520-
stack_bottom, stack_bottom, stack_bottom};
518+
bool odd_match;
519+
delimiter *openers_bottom[3][128];
520+
int i;
521+
522+
// initialize openers_bottom:
523+
for (i=0; i < 3; i++) {
524+
openers_bottom[i]['*'] = stack_bottom;
525+
openers_bottom[i]['_'] = stack_bottom;
526+
openers_bottom[i]['\''] = stack_bottom;
527+
openers_bottom[i]['"'] = stack_bottom;
528+
}
521529

522530
// move back to first relevant delim.
523531
while (closer != NULL && closer->previous != stack_bottom) {
@@ -527,36 +535,22 @@ static void process_emphasis(subject *subj, delimiter *stack_bottom) {
527535
// now move forward, looking for closers, and handling each
528536
while (closer != NULL) {
529537
if (closer->can_close) {
530-
switch (closer->delim_char) {
531-
case '"':
532-
openers_bottom_index = 0;
533-
break;
534-
case '\'':
535-
openers_bottom_index = 1;
536-
break;
537-
case '_':
538-
openers_bottom_index = 2;
539-
break;
540-
case '*':
541-
openers_bottom_index = 3 + (closer->length % 3);
542-
break;
543-
default:
544-
assert(false);
545-
}
546-
547538
// Now look backwards for first matching opener:
548539
opener = closer->previous;
549540
opener_found = false;
550-
while (opener != NULL && opener != openers_bottom[openers_bottom_index]) {
551-
if (opener->can_open && opener->delim_char == closer->delim_char) {
541+
odd_match = false;
542+
while (opener != NULL && opener != stack_bottom &&
543+
opener != openers_bottom[closer->length % 3][closer->delim_char]) {
544+
if (opener->can_open && opener->delim_char == closer->delim_char) {
552545
// interior closer of size 2 can't match opener of size 1
553546
// or of size 1 can't match 2
554-
if (!(closer->can_open || opener->can_close) ||
555-
((opener->length + closer->length) % 3) != 0) {
547+
odd_match = (closer->can_open || opener->can_close) &&
548+
((opener->length + closer->length) % 3 == 0);
549+
if (!odd_match) {
556550
opener_found = true;
557551
break;
558552
}
559-
}
553+
}
560554
opener = opener->previous;
561555
}
562556
old_closer = closer;
@@ -585,7 +579,8 @@ static void process_emphasis(subject *subj, delimiter *stack_bottom) {
585579
}
586580
if (!opener_found) {
587581
// set lower bound for future searches for openers
588-
openers_bottom[openers_bottom_index] = old_closer->previous;
582+
openers_bottom[old_closer->length % 3][old_closer->delim_char] =
583+
old_closer->previous;
589584
if (!old_closer->can_open) {
590585
// we can remove a closer that can't be an
591586
// opener, once we've seen there's no
@@ -1037,31 +1032,31 @@ static cmark_node *handle_newline(subject *subj) {
10371032
static bufsize_t subject_find_special_char(subject *subj, int options) {
10381033
// "\r\n\\`&_*[]<!"
10391034
static const int8_t SPECIAL_CHARS[256] = {
1040-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1041-
0, 0, 0, 0, 0,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