From: Fletcher T. Penney Date: Mon, 6 Mar 2017 19:50:39 +0000 (-0500) Subject: FIXED: Improve performance of checking document for metadata, which improves performa... X-Git-Tag: 6.0.0-b1^2~10 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d26d2e8668e234f21655e1c07a5f309f5527ae8d;p=multimarkdown FIXED: Improve performance of checking document for metadata, which improves performance when checking for possible transclusion --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d09be0..214ebde 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -567,6 +567,6 @@ ADD_MMD_TEST(mmd-6-latex "-t latex" MMD6Tests tex) ADD_MMD_TEST(mmd-6-odf "-t odf" MMD6Tests fodt) -ADD_MMD_TEST(pathologic "" ../build html) - ADD_MMD_TEST(pathologic-compat "-c" ../build html) + +ADD_MMD_TEST(pathologic "" ../build html) diff --git a/Sources/libMultiMarkdown/mmd.c b/Sources/libMultiMarkdown/mmd.c index 2d8ea2d..d53e759 100644 --- a/Sources/libMultiMarkdown/mmd.c +++ b/Sources/libMultiMarkdown/mmd.c @@ -1830,6 +1830,14 @@ void mmd_engine_parse_string(mmd_engine * e) { bool mmd_has_metadata(mmd_engine * e, size_t * end) { bool result = false; + if (!(scan_meta_line(&e->dstr->str[0]))) { + // First line is not metadata, so can't have metadata + // Saves the time of an unnecessary parse + // TODO: Need faster confirmation of actual metadata than full tokenizing + + return false; + } + // Free existing parse tree if (e->root) token_tree_free(e->root); diff --git a/Sources/libMultiMarkdown/scanners.c b/Sources/libMultiMarkdown/scanners.c index 9092f1b..bf59122 100644 --- a/Sources/libMultiMarkdown/scanners.c +++ b/Sources/libMultiMarkdown/scanners.c @@ -1,4 +1,4 @@ -/* Generated by re2c 0.14.3 on Sat Mar 4 20:43:41 2017 */ +/* Generated by re2c 0.14.3 on Mon Mar 6 14:49:25 2017 */ /** MultiMarkdown 6 -- Lightweight markup processor to produce HTML, LaTeX, and more. @@ -8863,20 +8863,8 @@ yy673: yy674: yych = *(marker = ++c); switch (yych) { - case '\t': goto yy679; + case '\t': case ' ': - case '!': - case '"': - case '#': - case '$': - case '%': - case '&': - case '\'': - case '(': - case ')': - case '*': - case '+': - case ',': case '-': case '.': case '0': @@ -8889,6 +8877,7 @@ yy674: case '7': case '8': case '9': + case ':': case 'A': case 'B': case 'C': @@ -8941,8 +8930,7 @@ yy674: case 'w': case 'x': case 'y': - case 'z': goto yy676; - case ':': goto yy681; + case 'z': goto yy677; default: goto yy673; } yy675: @@ -8951,21 +8939,10 @@ yy675: yy676: ++c; yych = *c; +yy677: switch (yych) { - case '\t': goto yy679; + case '\t': case ' ': - case '!': - case '"': - case '#': - case '$': - case '%': - case '&': - case '\'': - case '(': - case ')': - case '*': - case '+': - case ',': case '-': case '.': case '0': @@ -9031,47 +9008,38 @@ yy676: case 'x': case 'y': case 'z': goto yy676; - case ':': goto yy681; + case ':': goto yy679; default: goto yy678; } yy678: c = marker; goto yy673; yy679: - ++c; - yych = *c; - switch (yych) { - case '\t': - case ' ': goto yy679; - case ':': goto yy681; - default: goto yy678; - } -yy681: yych = *++c; switch (yych) { case 0x00: case '\n': case '\r': goto yy678; - default: goto yy682; + default: goto yy680; } -yy682: +yy680: ++c; yych = *c; switch (yych) { case 0x00: - case '\n': goto yy684; - case '\r': goto yy686; - default: goto yy682; + case '\n': goto yy682; + case '\r': goto yy684; + default: goto yy680; } -yy684: +yy682: ++c; -yy685: +yy683: { return (size_t)( c - start ); } -yy686: +yy684: ++c; switch ((yych = *c)) { - case '\n': goto yy684; - default: goto yy685; + case '\n': goto yy682; + default: goto yy683; } } @@ -9086,7 +9054,7 @@ size_t scan_meta_key(const char * c) { char yych; yych = *c; switch (yych) { - case '\n': goto yy689; + case '\n': goto yy687; case '0': case '1': case '2': @@ -9148,38 +9116,27 @@ size_t scan_meta_key(const char * c) { case 'w': case 'x': case 'y': - case 'z': goto yy690; - default: goto yy692; + case 'z': goto yy688; + default: goto yy690; } -yy689: +yy687: { return 0; } -yy690: +yy688: ++c; yych = *c; - goto yy694; -yy691: + goto yy692; +yy689: { return (size_t)( c - start ); } -yy692: +yy690: yych = *++c; - goto yy689; -yy693: + goto yy687; +yy691: ++c; yych = *c; -yy694: +yy692: switch (yych) { + case '\t': case ' ': - case '!': - case '"': - case '#': - case '$': - case '%': - case '&': - case '\'': - case '(': - case ')': - case '*': - case '+': - case ',': case '-': case '.': case '0': @@ -9244,8 +9201,8 @@ yy694: case 'w': case 'x': case 'y': - case 'z': goto yy693; - default: goto yy691; + case 'z': goto yy691; + default: goto yy689; } } @@ -9261,71 +9218,71 @@ size_t scan_definition(const char * c) { char yych; yych = *c; switch (yych) { - case '\n': goto yy697; - case ' ': goto yy698; - case ':': goto yy699; - default: goto yy700; + case '\n': goto yy695; + case ' ': goto yy696; + case ':': goto yy697; + default: goto yy698; } -yy697: +yy695: { return 0; } -yy698: +yy696: yych = *(marker = ++c); switch (yych) { - case ' ': goto yy705; - case ':': goto yy707; - default: goto yy697; + case ' ': goto yy703; + case ':': goto yy705; + default: goto yy695; } -yy699: +yy697: yych = *++c; switch (yych) { case 0x00: case '\n': - case '\r': goto yy697; - default: goto yy702; + case '\r': goto yy695; + default: goto yy700; } -yy700: +yy698: yych = *++c; - goto yy697; -yy701: + goto yy695; +yy699: ++c; yych = *c; -yy702: +yy700: switch (yych) { case 0x00: case '\n': - case '\r': goto yy703; + case '\r': goto yy701; case '\t': - case ' ': goto yy701; - default: goto yy704; + case ' ': goto yy699; + default: goto yy702; } -yy703: +yy701: { return (size_t)( c - start ); } -yy704: +yy702: yych = *++c; - goto yy703; -yy705: + goto yy701; +yy703: yych = *++c; switch (yych) { - case ' ': goto yy708; - case ':': goto yy707; - default: goto yy706; + case ' ': goto yy706; + case ':': goto yy705; + default: goto yy704; } -yy706: +yy704: c = marker; - goto yy697; -yy707: + goto yy695; +yy705: yych = *++c; switch (yych) { case 0x00: case '\n': - case '\r': goto yy706; - default: goto yy702; + case '\r': goto yy704; + default: goto yy700; } -yy708: +yy706: ++c; switch ((yych = *c)) { - case ':': goto yy707; - default: goto yy706; + case ':': goto yy705; + default: goto yy704; } } @@ -9346,14 +9303,14 @@ size_t scan_table_separator(const char * c) { case '+': case '-': case ':': - case '=': goto yy713; - case '\n': goto yy711; - case '|': goto yy712; - default: goto yy714; + case '=': goto yy711; + case '\n': goto yy709; + case '|': goto yy710; + default: goto yy712; } -yy711: +yy709: { return 0; } -yy712: +yy710: yych = *(marker = ++c); switch (yych) { case 0x00: @@ -9365,10 +9322,10 @@ yy712: case '-': case ':': case '=': - case '|': goto yy724; - default: goto yy711; + case '|': goto yy722; + default: goto yy709; } -yy713: +yy711: yych = *(marker = ++c); switch (yych) { case '\t': @@ -9376,33 +9333,33 @@ yy713: case '+': case '-': case ':': - case '=': goto yy718; - case '|': goto yy715; - default: goto yy711; + case '=': goto yy716; + case '|': goto yy713; + default: goto yy709; } -yy714: +yy712: yych = *++c; - goto yy711; -yy715: + goto yy709; +yy713: ++c; yych = *c; switch (yych) { case 0x00: - case '\n': goto yy720; + case '\n': goto yy718; case '\t': case ' ': case '+': case '-': case ':': case '=': - case '|': goto yy715; - case '\r': goto yy722; - default: goto yy717; + case '|': goto yy713; + case '\r': goto yy720; + default: goto yy715; } -yy717: +yy715: c = marker; - goto yy711; -yy718: + goto yy709; +yy716: ++c; yych = *c; switch (yych) { @@ -9411,36 +9368,36 @@ yy718: case '+': case '-': case ':': - case '=': goto yy718; - case '|': goto yy715; - default: goto yy717; + case '=': goto yy716; + case '|': goto yy713; + default: goto yy715; } -yy720: +yy718: ++c; -yy721: +yy719: { return (size_t)( c - start ); } -yy722: +yy720: yych = *++c; switch (yych) { - case '\n': goto yy720; - default: goto yy721; + case '\n': goto yy718; + default: goto yy719; } -yy723: +yy721: ++c; yych = *c; -yy724: +yy722: switch (yych) { case 0x00: - case '\n': goto yy720; + case '\n': goto yy718; case '\t': case ' ': case '+': case '-': case ':': case '=': - case '|': goto yy723; - case '\r': goto yy722; - default: goto yy717; + case '|': goto yy721; + case '\r': goto yy720; + default: goto yy715; } } @@ -9456,234 +9413,234 @@ size_t scan_alignment_string(const char * c) { yych = *c; switch (yych) { case '\t': - case ' ': goto yy728; - case '\n': goto yy727; + case ' ': goto yy726; + case '\n': goto yy725; case '-': - case '=': goto yy730; - case ':': goto yy729; - default: goto yy731; + case '=': goto yy728; + case ':': goto yy727; + default: goto yy729; } -yy727: +yy725: { return 0; } -yy728: +yy726: yych = *(marker = ++c); switch (yych) { case '\t': - case ' ': goto yy770; + case ' ': goto yy768; case '-': - case '=': goto yy734; - case ':': goto yy769; - default: goto yy727; + case '=': goto yy732; + case ':': goto yy767; + default: goto yy725; } -yy729: +yy727: yych = *(marker = ++c); switch (yych) { case '-': - case '=': goto yy746; - default: goto yy727; + case '=': goto yy744; + default: goto yy725; } -yy730: +yy728: yych = *(marker = ++c); switch (yych) { case '-': - case '=': goto yy734; - case ':': goto yy732; - default: goto yy727; + case '=': goto yy732; + case ':': goto yy730; + default: goto yy725; } -yy731: +yy729: yych = *++c; - goto yy727; -yy732: + goto yy725; +yy730: yych = *++c; switch (yych) { - case '+': goto yy741; - default: goto yy737; + case '+': goto yy739; + default: goto yy735; } -yy733: +yy731: c = marker; - goto yy727; -yy734: + goto yy725; +yy732: ++c; yych = *c; switch (yych) { case '-': - case '=': goto yy734; - case ':': goto yy732; - default: goto yy733; + case '=': goto yy732; + case ':': goto yy730; + default: goto yy731; } -yy736: +yy734: ++c; yych = *c; -yy737: +yy735: switch (yych) { case 0x00: case '\n': - case '|': goto yy738; + case '|': goto yy736; case '\t': - case ' ': goto yy736; - case '\r': goto yy740; - default: goto yy733; + case ' ': goto yy734; + case '\r': goto yy738; + default: goto yy731; } -yy738: +yy736: ++c; -yy739: +yy737: { return ALIGN_RIGHT; } -yy740: +yy738: yych = *++c; switch (yych) { - case '\n': goto yy738; - default: goto yy739; + case '\n': goto yy736; + default: goto yy737; } -yy741: +yy739: ++c; yych = *c; switch (yych) { case 0x00: case '\n': - case '|': goto yy743; + case '|': goto yy741; case '\t': - case ' ': goto yy741; - case '\r': goto yy745; - default: goto yy733; + case ' ': goto yy739; + case '\r': goto yy743; + default: goto yy731; } -yy743: +yy741: ++c; -yy744: +yy742: { return ALIGN_WRAP | ALIGN_RIGHT; } -yy745: +yy743: yych = *++c; switch (yych) { - case '\n': goto yy743; - default: goto yy744; + case '\n': goto yy741; + default: goto yy742; } -yy746: +yy744: ++c; yych = *c; switch (yych) { case 0x00: case '\n': - case '|': goto yy750; + case '|': goto yy748; case '\t': - case ' ': goto yy748; - case '\r': goto yy752; - case '+': goto yy754; + case ' ': goto yy746; + case '\r': goto yy750; + case '+': goto yy752; case '-': - case '=': goto yy746; - case ':': goto yy753; - default: goto yy733; + case '=': goto yy744; + case ':': goto yy751; + default: goto yy731; } -yy748: +yy746: ++c; yych = *c; switch (yych) { case 0x00: case '\n': - case '|': goto yy750; + case '|': goto yy748; case '\t': - case ' ': goto yy748; - case '\r': goto yy752; - default: goto yy733; + case ' ': goto yy746; + case '\r': goto yy750; + default: goto yy731; } -yy750: +yy748: ++c; -yy751: +yy749: { return ALIGN_LEFT; } -yy752: +yy750: yych = *++c; switch (yych) { - case '\n': goto yy750; - default: goto yy751; + case '\n': goto yy748; + default: goto yy749; } -yy753: +yy751: yych = *++c; switch (yych) { - case '+': goto yy759; - default: goto yy762; + case '+': goto yy757; + default: goto yy760; } -yy754: +yy752: ++c; yych = *c; switch (yych) { case 0x00: case '\n': - case '|': goto yy756; + case '|': goto yy754; case '\t': - case ' ': goto yy754; - case '\r': goto yy758; - default: goto yy733; + case ' ': goto yy752; + case '\r': goto yy756; + default: goto yy731; } -yy756: +yy754: ++c; -yy757: +yy755: { return ALIGN_WRAP | ALIGN_LEFT; } -yy758: +yy756: yych = *++c; switch (yych) { - case '\n': goto yy756; - default: goto yy757; + case '\n': goto yy754; + default: goto yy755; } -yy759: +yy757: ++c; yych = *c; switch (yych) { case 0x00: case '\n': - case '|': goto yy766; + case '|': goto yy764; case '\t': - case ' ': goto yy759; - case '\r': goto yy768; - default: goto yy733; + case ' ': goto yy757; + case '\r': goto yy766; + default: goto yy731; } -yy761: +yy759: ++c; yych = *c; -yy762: +yy760: switch (yych) { case 0x00: case '\n': - case '|': goto yy763; + case '|': goto yy761; case '\t': - case ' ': goto yy761; - case '\r': goto yy765; - default: goto yy733; + case ' ': goto yy759; + case '\r': goto yy763; + default: goto yy731; } -yy763: +yy761: ++c; -yy764: +yy762: { return ALIGN_CENTER; } -yy765: +yy763: yych = *++c; switch (yych) { - case '\n': goto yy763; - default: goto yy764; + case '\n': goto yy761; + default: goto yy762; } -yy766: +yy764: ++c; -yy767: +yy765: { return ALIGN_WRAP | ALIGN_CENTER; } -yy768: +yy766: yych = *++c; switch (yych) { - case '\n': goto yy766; - default: goto yy767; + case '\n': goto yy764; + default: goto yy765; } -yy769: +yy767: yych = *++c; switch (yych) { case '-': - case '=': goto yy746; - default: goto yy733; + case '=': goto yy744; + default: goto yy731; } -yy770: +yy768: ++c; yych = *c; switch (yych) { case '\t': - case ' ': goto yy770; + case ' ': goto yy768; case '-': - case '=': goto yy734; - case ':': goto yy769; - default: goto yy733; + case '=': goto yy732; + case ':': goto yy767; + default: goto yy731; } } @@ -9701,49 +9658,49 @@ size_t scan_destination(const char * c) { case 0x00: case '\t': case '\r': - case ' ': goto yy778; - case '\n': goto yy774; - case '<': goto yy775; - default: goto yy777; + case ' ': goto yy776; + case '\n': goto yy772; + case '<': goto yy773; + default: goto yy775; } -yy774: +yy772: { return 0; } -yy775: +yy773: ++c; yych = *c; - goto yy782; -yy776: + goto yy780; +yy774: { return (size_t)( c - start ); } -yy777: +yy775: yych = *++c; - goto yy780; -yy778: + goto yy778; +yy776: yych = *++c; - goto yy774; -yy779: + goto yy772; +yy777: ++c; yych = *c; -yy780: +yy778: switch (yych) { case 0x00: case '\t': case '\n': case '\r': - case ' ': goto yy776; - default: goto yy779; + case ' ': goto yy774; + default: goto yy777; } -yy781: +yy779: ++c; yych = *c; -yy782: +yy780: switch (yych) { case 0x00: case '\t': case '\n': case '\r': - case ' ': goto yy776; - case '>': goto yy779; - default: goto yy781; + case ' ': goto yy774; + case '>': goto yy777; + default: goto yy779; } } @@ -9759,79 +9716,79 @@ size_t scan_title(const char * c) { char yych; yych = *c; switch (yych) { - case '\n': goto yy785; - case '"': goto yy786; - case '\'': goto yy787; - case '(': goto yy788; - default: goto yy789; + case '\n': goto yy783; + case '"': goto yy784; + case '\'': goto yy785; + case '(': goto yy786; + default: goto yy787; } -yy785: +yy783: { return 0; } -yy786: +yy784: yych = *(marker = ++c); switch (yych) { case 0x00: case '\n': - case '\r': goto yy785; - default: goto yy798; + case '\r': goto yy783; + default: goto yy796; } -yy787: +yy785: yych = *(marker = ++c); switch (yych) { case 0x00: case '\n': - case '\r': goto yy785; - default: goto yy796; + case '\r': goto yy783; + default: goto yy794; } -yy788: +yy786: yych = *(marker = ++c); switch (yych) { case 0x00: case '\n': - case '\r': goto yy785; - default: goto yy791; + case '\r': goto yy783; + default: goto yy789; } -yy789: +yy787: yych = *++c; - goto yy785; -yy790: + goto yy783; +yy788: ++c; yych = *c; -yy791: +yy789: switch (yych) { case 0x00: case '\n': - case '\r': goto yy792; - case ')': goto yy793; - default: goto yy790; + case '\r': goto yy790; + case ')': goto yy791; + default: goto yy788; } -yy792: +yy790: c = marker; - goto yy785; -yy793: + goto yy783; +yy791: ++c; { return (size_t)( c - start ); } -yy795: +yy793: ++c; yych = *c; -yy796: +yy794: switch (yych) { case 0x00: case '\n': - case '\r': goto yy792; - case '\'': goto yy793; - default: goto yy795; + case '\r': goto yy790; + case '\'': goto yy791; + default: goto yy793; } -yy797: +yy795: ++c; yych = *c; -yy798: +yy796: switch (yych) { case 0x00: case '\n': - case '\r': goto yy792; - case '"': goto yy793; - default: goto yy797; + case '\r': goto yy790; + case '"': goto yy791; + default: goto yy795; } } @@ -9846,106 +9803,106 @@ size_t scan_setext(const char * c) { char yych; yych = *c; switch (yych) { - case '\n': goto yy801; - case ' ': goto yy802; - case '-': goto yy804; - case '=': goto yy803; - default: goto yy805; + case '\n': goto yy799; + case ' ': goto yy800; + case '-': goto yy802; + case '=': goto yy801; + default: goto yy803; } -yy801: +yy799: { return 0; } -yy802: +yy800: yych = *(marker = ++c); switch (yych) { - case ' ': goto yy817; - case '-': goto yy818; - case '=': goto yy819; - default: goto yy801; + case ' ': goto yy815; + case '-': goto yy816; + case '=': goto yy817; + default: goto yy799; } -yy803: +yy801: yych = *(marker = ++c); switch (yych) { - case '=': goto yy812; - default: goto yy801; + case '=': goto yy810; + default: goto yy799; } -yy804: +yy802: yych = *(marker = ++c); switch (yych) { - case '-': goto yy806; - default: goto yy801; + case '-': goto yy804; + default: goto yy799; } -yy805: +yy803: yych = *++c; - goto yy801; -yy806: + goto yy799; +yy804: ++c; yych = *c; switch (yych) { case 0x00: - case '\n': goto yy809; - case '\r': goto yy811; - case '-': goto yy806; - default: goto yy808; + case '\n': goto yy807; + case '\r': goto yy809; + case '-': goto yy804; + default: goto yy806; } -yy808: +yy806: c = marker; - goto yy801; -yy809: + goto yy799; +yy807: ++c; -yy810: +yy808: { return (size_t)( c - start ); } -yy811: +yy809: yych = *++c; switch (yych) { - case '\n': goto yy809; - default: goto yy810; + case '\n': goto yy807; + default: goto yy808; } -yy812: +yy810: ++c; yych = *c; switch (yych) { case 0x00: - case '\n': goto yy814; - case '\r': goto yy816; - case '=': goto yy812; - default: goto yy808; + case '\n': goto yy812; + case '\r': goto yy814; + case '=': goto yy810; + default: goto yy806; } -yy814: +yy812: ++c; -yy815: +yy813: { return (size_t)( c - start ); } -yy816: +yy814: yych = *++c; switch (yych) { - case '\n': goto yy814; - default: goto yy815; + case '\n': goto yy812; + default: goto yy813; } -yy817: +yy815: yych = *++c; switch (yych) { - case ' ': goto yy820; - case '-': goto yy818; - case '=': goto yy819; - default: goto yy808; + case ' ': goto yy818; + case '-': goto yy816; + case '=': goto yy817; + default: goto yy806; } -yy818: +yy816: yych = *++c; switch (yych) { - case '-': goto yy806; - default: goto yy808; + case '-': goto yy804; + default: goto yy806; } -yy819: +yy817: yych = *++c; switch (yych) { - case '=': goto yy812; - default: goto yy808; + case '=': goto yy810; + default: goto yy806; } -yy820: +yy818: ++c; switch ((yych = *c)) { - case '-': goto yy818; - case '=': goto yy819; - default: goto yy808; + case '-': goto yy816; + case '=': goto yy817; + default: goto yy806; } } diff --git a/Sources/libMultiMarkdown/scanners.re b/Sources/libMultiMarkdown/scanners.re index 1e3f895..ef4bcc3 100644 --- a/Sources/libMultiMarkdown/scanners.re +++ b/Sources/libMultiMarkdown/scanners.re @@ -136,7 +136,7 @@ fence_end = non_indent [`~]{3,} sp nl_eof; - meta_key = [A-Za-z0-9] [A-Za-z0-9_ -\.]*; + meta_key = [A-Za-z0-9] [A-Za-z0-9_ \t\-\.]*; meta_value = [^\n\r\x00]+;