Improvements to the gperf flow
This commit is contained in:
parent
28946e6ea8
commit
2508c4b5c7
4 changed files with 82 additions and 93 deletions
8
Makefile
8
Makefile
|
@ -30,7 +30,8 @@ HOEDOWN_SRC=\
|
|||
src/autolink.o \
|
||||
src/escape.o \
|
||||
src/html.o \
|
||||
src/html_smartypants.o \
|
||||
src/html_blocks.o \
|
||||
src/html_smartypants.o
|
||||
|
||||
all: libhoedown.so hoedown smartypants html_blocks
|
||||
|
||||
|
@ -53,10 +54,9 @@ smartypants: examples/smartypants.o $(HOEDOWN_SRC)
|
|||
$(CC) $(LDFLAGS) $^ -o $@
|
||||
|
||||
# perfect hashing
|
||||
html_blocks: src/html_blocks.h
|
||||
|
||||
src/html_blocks.h: html_block_names.txt
|
||||
gperf -N hoedown_find_block_tag -H hash_block_tag -C -c -E -S 1 --ignore-case $^ > $@
|
||||
src/html_blocks.c: html_block_names.gperf
|
||||
gperf -L ANSI-C -N hoedown_find_block_tag -c -C -E -S 1 --ignore-case -m100 $^ > $@
|
||||
|
||||
test: hoedown
|
||||
perl test/MarkdownTest_1.0.3/MarkdownTest.pl \
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
##
|
||||
p
|
||||
dl
|
||||
h1
|
||||
|
@ -15,11 +14,11 @@ ins
|
|||
pre
|
||||
form
|
||||
math
|
||||
style
|
||||
table
|
||||
figure
|
||||
iframe
|
||||
script
|
||||
style
|
||||
fieldset
|
||||
noscript
|
||||
blockquote
|
|
@ -1,5 +1,5 @@
|
|||
/* C code produced by gperf version 3.0.3 */
|
||||
/* Command-line: gperf -N hoedown_find_block_tag -H hash_block_tag -C -c -E -P -S 1 --ignore-case html_block_names.txt */
|
||||
/* ANSI-C code produced by gperf version 3.0.3 */
|
||||
/* Command-line: gperf -L ANSI-C -N hoedown_find_block_tag -c -C -E -S 1 --ignore-case -m100 html_block_names.gperf */
|
||||
/* Computed positions: -k'1-2' */
|
||||
|
||||
#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
|
||||
|
@ -26,10 +26,10 @@
|
|||
&& ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \
|
||||
&& ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126))
|
||||
/* The character set is not based on ISO-646. */
|
||||
error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gnu-gperf@gnu.org>."
|
||||
#error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gnu-gperf@gnu.org>."
|
||||
#endif
|
||||
|
||||
/* maximum key range = 37, duplicates = 0 */
|
||||
/* maximum key range = 24, duplicates = 0 */
|
||||
|
||||
#ifndef GPERF_DOWNCASE
|
||||
#define GPERF_DOWNCASE 1
|
||||
|
@ -59,10 +59,7 @@ static unsigned char gperf_downcase[256] =
|
|||
#ifndef GPERF_CASE_STRNCMP
|
||||
#define GPERF_CASE_STRNCMP 1
|
||||
static int
|
||||
gperf_case_strncmp (s1, s2, n)
|
||||
register const char *s1;
|
||||
register const char *s2;
|
||||
register unsigned int n;
|
||||
gperf_case_strncmp (register const char *s1, register const char *s2, register unsigned int n)
|
||||
{
|
||||
for (; n > 0;)
|
||||
{
|
||||
|
@ -87,38 +84,36 @@ inline
|
|||
#endif
|
||||
#endif
|
||||
static unsigned int
|
||||
hash_block_tag (str, len)
|
||||
register const char *str;
|
||||
register unsigned int len;
|
||||
hash (register const char *str, register unsigned int len)
|
||||
{
|
||||
static const unsigned char asso_values[] =
|
||||
{
|
||||
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
|
||||
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
|
||||
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
|
||||
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
|
||||
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
|
||||
8, 30, 25, 20, 15, 10, 38, 38, 38, 38,
|
||||
38, 38, 38, 38, 38, 38, 0, 38, 0, 38,
|
||||
5, 5, 5, 15, 0, 38, 38, 0, 15, 10,
|
||||
0, 38, 38, 15, 0, 5, 38, 38, 38, 38,
|
||||
38, 38, 38, 38, 38, 38, 38, 38, 0, 38,
|
||||
0, 38, 5, 5, 5, 15, 0, 38, 38, 0,
|
||||
15, 10, 0, 38, 38, 15, 0, 5, 38, 38,
|
||||
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
|
||||
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
|
||||
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
|
||||
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
|
||||
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
|
||||
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
|
||||
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
|
||||
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
|
||||
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
|
||||
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
|
||||
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
|
||||
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
|
||||
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
|
||||
38, 38, 38, 38, 38, 38, 38
|
||||
25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
|
||||
25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
|
||||
25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
|
||||
25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
|
||||
25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
|
||||
22, 21, 19, 18, 16, 0, 25, 25, 25, 25,
|
||||
25, 25, 25, 25, 25, 25, 1, 25, 0, 25,
|
||||
1, 0, 0, 13, 0, 25, 25, 11, 2, 1,
|
||||
0, 25, 25, 5, 0, 2, 25, 25, 25, 25,
|
||||
25, 25, 25, 25, 25, 25, 25, 25, 1, 25,
|
||||
0, 25, 1, 0, 0, 13, 0, 25, 25, 11,
|
||||
2, 1, 0, 25, 25, 5, 0, 2, 25, 25,
|
||||
25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
|
||||
25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
|
||||
25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
|
||||
25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
|
||||
25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
|
||||
25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
|
||||
25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
|
||||
25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
|
||||
25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
|
||||
25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
|
||||
25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
|
||||
25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
|
||||
25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
|
||||
25, 25, 25, 25, 25, 25, 25
|
||||
};
|
||||
register int hval = (int)len;
|
||||
|
||||
|
@ -141,9 +136,7 @@ __attribute__ ((__gnu_inline__))
|
|||
#endif
|
||||
#endif
|
||||
const char *
|
||||
hoedown_find_block_tag (str, len)
|
||||
register const char *str;
|
||||
register unsigned int len;
|
||||
hoedown_find_block_tag (register const char *str, register unsigned int len)
|
||||
{
|
||||
enum
|
||||
{
|
||||
|
@ -151,12 +144,12 @@ hoedown_find_block_tag (str, len)
|
|||
MIN_WORD_LENGTH = 1,
|
||||
MAX_WORD_LENGTH = 10,
|
||||
MIN_HASH_VALUE = 1,
|
||||
MAX_HASH_VALUE = 37
|
||||
MAX_HASH_VALUE = 24
|
||||
};
|
||||
|
||||
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
|
||||
{
|
||||
register int key = hash_block_tag (str, len);
|
||||
register int key = hash (str, len);
|
||||
|
||||
if (key <= MAX_HASH_VALUE && key >= MIN_HASH_VALUE)
|
||||
{
|
||||
|
@ -168,74 +161,74 @@ hoedown_find_block_tag (str, len)
|
|||
resword = "p";
|
||||
goto compare;
|
||||
case 1:
|
||||
resword = "dl";
|
||||
resword = "h6";
|
||||
goto compare;
|
||||
case 2:
|
||||
resword = "div";
|
||||
goto compare;
|
||||
case 3:
|
||||
resword = "math";
|
||||
resword = "del";
|
||||
goto compare;
|
||||
case 4:
|
||||
resword = "form";
|
||||
goto compare;
|
||||
case 5:
|
||||
resword = "table";
|
||||
goto compare;
|
||||
case 6:
|
||||
resword = "ul";
|
||||
goto compare;
|
||||
case 7:
|
||||
resword = "del";
|
||||
goto compare;
|
||||
case 8:
|
||||
resword = "form";
|
||||
goto compare;
|
||||
case 9:
|
||||
resword = "blockquote";
|
||||
goto compare;
|
||||
case 10:
|
||||
resword = "figure";
|
||||
goto compare;
|
||||
case 11:
|
||||
resword = "ol";
|
||||
goto compare;
|
||||
case 12:
|
||||
resword = "fieldset";
|
||||
goto compare;
|
||||
case 14:
|
||||
resword = "h1";
|
||||
goto compare;
|
||||
case 16:
|
||||
resword = "h6";
|
||||
goto compare;
|
||||
case 17:
|
||||
case 7:
|
||||
resword = "pre";
|
||||
goto compare;
|
||||
case 20:
|
||||
resword = "script";
|
||||
case 8:
|
||||
resword = "fieldset";
|
||||
goto compare;
|
||||
case 21:
|
||||
resword = "h5";
|
||||
goto compare;
|
||||
case 22:
|
||||
case 9:
|
||||
resword = "noscript";
|
||||
goto compare;
|
||||
case 24:
|
||||
case 10:
|
||||
resword = "script";
|
||||
goto compare;
|
||||
case 11:
|
||||
resword = "style";
|
||||
goto compare;
|
||||
case 25:
|
||||
resword = "iframe";
|
||||
case 12:
|
||||
resword = "dl";
|
||||
goto compare;
|
||||
case 26:
|
||||
resword = "h4";
|
||||
case 13:
|
||||
resword = "ol";
|
||||
goto compare;
|
||||
case 27:
|
||||
case 14:
|
||||
resword = "ul";
|
||||
goto compare;
|
||||
case 15:
|
||||
resword = "math";
|
||||
goto compare;
|
||||
case 16:
|
||||
resword = "ins";
|
||||
goto compare;
|
||||
case 31:
|
||||
case 17:
|
||||
resword = "h5";
|
||||
goto compare;
|
||||
case 18:
|
||||
resword = "iframe";
|
||||
goto compare;
|
||||
case 19:
|
||||
resword = "h4";
|
||||
goto compare;
|
||||
case 20:
|
||||
resword = "h3";
|
||||
goto compare;
|
||||
case 36:
|
||||
case 21:
|
||||
resword = "blockquote";
|
||||
goto compare;
|
||||
case 22:
|
||||
resword = "h2";
|
||||
goto compare;
|
||||
case 23:
|
||||
resword = "h1";
|
||||
goto compare;
|
||||
}
|
||||
return 0;
|
||||
compare:
|
|
@ -19,10 +19,7 @@
|
|||
|
||||
#define MKD_LI_END 8 /* internal list flag */
|
||||
|
||||
#define gperf_case_strncmp(s1, s2, n) strncasecmp(s1, s2, n)
|
||||
#define GPERF_DOWNCASE 1
|
||||
#define GPERF_CASE_STRNCMP 1
|
||||
#include "html_blocks.h"
|
||||
const char *hoedown_find_block_tag(const char *str, unsigned int len);
|
||||
|
||||
/***************
|
||||
* LOCAL TYPES *
|
||||
|
|
Loading…
Reference in a new issue