cmark

My personal build of CMark ✏️

Commit
64a4c3767cf5a395bfe5157dd4bc144caebf270f
Parent
a8d5bd452ae8a7b2d3285a85a9117f95ed1732cc
Author
John MacFarlane <jgm@berkeley.edu>
Date

Cleaned up setting of lower bounds for openers.

We now use a much smaller array.

Diffstat

1 file changed, 26 insertions, 19 deletions

Status File Name N° Changes Insertions Deletions
Modified src/inlines.c 45 26 19
diff --git a/src/inlines.c b/src/inlines.c
@@ -515,17 +515,10 @@ static void process_emphasis(subject *subj, delimiter *stack_bottom) {
   delimiter *opener;
   delimiter *old_closer;
   bool opener_found;
-  bool odd_match;
-  delimiter *openers_bottom[3][128];
-  int i;
-
-  // initialize openers_bottom:
-  for (i=0; i < 3; i++) {
-    openers_bottom[i]['*'] = stack_bottom;
-    openers_bottom[i]['_'] = stack_bottom;
-    openers_bottom[i]['\''] = stack_bottom;
-    openers_bottom[i]['"'] = stack_bottom;
-  }
+  int openers_bottom_index;
+  delimiter *openers_bottom[6] = { stack_bottom, stack_bottom,
+	                           stack_bottom, stack_bottom,
+				   stack_bottom, stack_bottom };
 
   // move back to first relevant delim.
   while (closer != NULL && closer->previous != stack_bottom) {
@@ -535,18 +528,33 @@ static void process_emphasis(subject *subj, delimiter *stack_bottom) {
   // now move forward, looking for closers, and handling each
   while (closer != NULL) {
     if (closer->can_close) {
+       switch (closer->delim_char) {
+	 case '"':
+	   openers_bottom_index = 0;
+	   break;
+	 case '\'':
+	   openers_bottom_index = 1;
+	   break;
+	 case '_':
+	   openers_bottom_index = 2;
+	   break;
+	 case '*':
+	   openers_bottom_index = 3 + (closer->length % 3);
+	   break;
+	 default:
+	   assert(false);
+      }
+
       // Now look backwards for first matching opener:
       opener = closer->previous;
       opener_found = false;
-      odd_match = false;
-      while (opener != NULL && opener != stack_bottom &&
-             opener != openers_bottom[closer->length % 3][closer->delim_char]) {
+      while (opener != NULL &&
+	     opener != openers_bottom[openers_bottom_index]) {
 	if (opener->can_open && opener->delim_char == closer->delim_char) {
           // interior closer of size 2 can't match opener of size 1
           // or of size 1 can't match 2
-          odd_match = (closer->can_open || opener->can_close) &&
-                      ((opener->length + closer->length) % 3 == 0);
-          if (!odd_match) {
+          if (!(closer->can_open || opener->can_close) ||
+                      ((opener->length + closer->length) % 3) != 0) {
             opener_found = true;
             break;
           }
@@ -579,8 +587,7 @@ static void process_emphasis(subject *subj, delimiter *stack_bottom) {
       }
       if (!opener_found) {
         // set lower bound for future searches for openers
-        openers_bottom[old_closer->length % 3][old_closer->delim_char] =
-		old_closer->previous;
+        openers_bottom[openers_bottom_index] = old_closer->previous;
         if (!old_closer->can_open) {
           // we can remove a closer that can't be an
           // opener, once we've seen there's no