Skip to content

Commit

Permalink
Improvements to the gperf flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Devin Torres committed Sep 21, 2013
1 parent 28946e6 commit 2508c4b
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 82 deletions.
8 changes: 4 additions & 4 deletions Makefile
Expand Up @@ -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

Expand All @@ -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 \
Expand Down
3 changes: 1 addition & 2 deletions html_block_names.txt → html_block_names.gperf
@@ -1,4 +1,3 @@
##
p
dl
h1
Expand All @@ -15,11 +14,11 @@ ins
pre
form
math
style
table
figure
iframe
script
style
fieldset
noscript
blockquote
137 changes: 65 additions & 72 deletions src/html_blocks.h → src/html_blocks.c
@@ -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) \
Expand All @@ -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
Expand Down Expand Up @@ -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;)
{
Expand All @@ -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;

Expand All @@ -141,22 +136,20 @@ __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
{
TOTAL_KEYWORDS = 24,
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)
{
Expand All @@ -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";
resword = "figure";
goto compare;
case 7:
resword = "del";
resword = "pre";
goto compare;
case 8:
resword = "form";
resword = "fieldset";
goto compare;
case 9:
resword = "blockquote";
resword = "noscript";
goto compare;
case 10:
resword = "figure";
resword = "script";
goto compare;
case 11:
resword = "ol";
resword = "style";
goto compare;
case 12:
resword = "fieldset";
resword = "dl";
goto compare;
case 13:
resword = "ol";
goto compare;
case 14:
resword = "h1";
resword = "ul";
goto compare;
case 15:
resword = "math";
goto compare;
case 16:
resword = "h6";
resword = "ins";
goto compare;
case 17:
resword = "pre";
goto compare;
case 20:
resword = "script";
goto compare;
case 21:
resword = "h5";
goto compare;
case 22:
resword = "noscript";
goto compare;
case 24:
resword = "style";
goto compare;
case 25:
case 18:
resword = "iframe";
goto compare;
case 26:
case 19:
resword = "h4";
goto compare;
case 27:
resword = "ins";
goto compare;
case 31:
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:
Expand Down
5 changes: 1 addition & 4 deletions src/markdown.c
Expand Up @@ -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 *
Expand Down

0 comments on commit 2508c4b

Please sign in to comment.