aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tokenize.c
diff options
authorLinus Torvalds <torvalds@tove.osdl.org>2004-11-09 14:16:30 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-07 21:04:15 -0700
commit97a48462f36bff375bfc9f73231bd3a07e0b1990 (patch)
tree0a4588c2cd578d9653aee903364edcf3440c60d7 /tokenize.c
parent63c38b866407ebe12a5f8451fa758fc31f1b184f (diff)
downloadsparse-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.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/tokenize.c b/tokenize.c
index 7cd24565..defc8819 100644
--- a/tokenize.c
+++ b/tokenize.c
@@ -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;