diff options
Diffstat (limited to 'src/alf.c')
| -rw-r--r-- | src/alf.c | 30 |
1 files changed, 25 insertions, 5 deletions
@@ -199,21 +199,41 @@ void store_token(int tok) { search backwards, the tokens are stored with longer ones later in the list. */ int match_token(int pos) { - int i, maxlen; + int i, len, maxlen; + token_t *t; + u8 *p, *q; maxlen = input_len - pos; for(i = curr_token - 1; i >= INIT_TOKEN; i--) { + t = &tokentab[i]; + /* don't search past the end of the input */ - if(tokentab[i].length > maxlen) continue; + if(t->length > maxlen) continue; /* if the first char doesn't match, don't bother with memcmp. this is a 5x speedup (!) */ - if(input_buf[pos] != *(tokentab[i].start)) continue; + if(input_buf[pos] != *(t->start)) continue; - /* memcmp is where alf spends most of its time. */ - if(memcmp(&input_buf[pos], tokentab[i].start, tokentab[i].length) == 0) + /* this is where alf spends most of its time. + using memcmp is noticeably slower than the code below. */ + /* + if(memcmp(&input_buf[pos], t->start, t->length) == 0) return i; + */ + + /* inline memcmp replacement of sorts. I don't think it's really + faster than memcmp(), it only seems that way because there's + no function call overhead. ~20% speedup. */ + len = t->length; + p = &input_buf[pos]; + q = t->start; + while(len) { + if(*p != *q) break; + p++; q++; + len--; + } + if(!len) return i; } /* hard-coded single character tokens map to their values, no need |
