diff options
| author | Linus Torvalds <torvalds@tove.osdl.org> | 2004-11-09 14:16:30 -0700 |
|---|---|---|
| committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-07 21:04:15 -0700 |
| commit | 97a48462f36bff375bfc9f73231bd3a07e0b1990 (patch) | |
| tree | 0a4588c2cd578d9653aee903364edcf3440c60d7 /tokenize.c | |
| parent | 63c38b866407ebe12a5f8451fa758fc31f1b184f (diff) | |
| download | sparse-dev-97a48462f36bff375bfc9f73231bd3a07e0b1990.tar.gz | |
Uninline "nextchar()", and optimize.
This is the hottest function by far, and we're
better off looking up the (few) special cases
in an array than doing a switch-statement.
Diffstat (limited to 'tokenize.c')
| -rw-r--r-- | tokenize.c | 14 |
1 files changed, 10 insertions, 4 deletions
@@ -277,13 +277,21 @@ got_eof: * Slow path (including the logics with line-splicing and EOF sanity * checks) is in nextchar_slow(). */ -static inline int nextchar(stream_t *stream) +static int nextchar(stream_t *stream) { int offset = stream->offset; if (offset < stream->size) { int c = stream->buffer[offset++]; + static char special[256] = { + ['\r'] = 1, ['\n'] = 1, ['\\'] = 1 + }; unsigned char next; + if (!special[c]) { + stream->offset = offset; + stream->pos.pos++; + return c; + } switch (c) { case '\r': break; @@ -293,14 +301,12 @@ static inline int nextchar(stream_t *stream) stream->pos.newline = 1; stream->pos.pos = 0; return '\n'; - case '\\': + default: /* '\\' */ if (offset >= stream->size) break; next = stream->buffer[offset]; if (next == '\n' || next == '\r') break; - /* fallthru */ - default: stream->offset = offset; stream->pos.pos++; return c; |
