Added lexer token caching for improved performance

git-svn-id: http://picoc.googlecode.com/svn/trunk@29 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
zik.saleeba 2009-01-05 04:52:33 +00:00
parent 883c862474
commit ef8969d975

24
lex.c
View file

@ -159,7 +159,7 @@ enum LexToken LexGetComment(struct LexState *Lexer, char NextChar, union AnyValu
return LexGetToken(Lexer, Value);
}
enum LexToken LexGetToken(struct LexState *Lexer, union AnyValue *Value)
enum LexToken LexGetTokenUncached(struct LexState *Lexer, union AnyValue *Value)
{
char ThisChar;
char NextChar;
@ -215,6 +215,28 @@ enum LexToken LexGetToken(struct LexState *Lexer, union AnyValue *Value)
return TokenEOF;
}
enum LexToken LexGetToken(struct LexState *Lexer, union AnyValue *Value)
{
static const char *CachedPos = NULL;
static union AnyValue CachedValue;
static struct LexState CachedLexer;
static enum LexToken CachedToken;
if (Lexer->Pos == CachedPos)
{
*Value = CachedValue;
*Lexer = CachedLexer;
}
else
{
CachedToken = LexGetTokenUncached(Lexer, Value);
CachedLexer = *Lexer;
CachedValue = *Value;
}
return CachedToken;
}
enum LexToken LexGetPlainToken(struct LexState *Lexer)
{
union AnyValue Value;