Skip to content

Commit

Permalink
Merge pull request #3808 from yebblies/tokalloc
Browse files Browse the repository at this point in the history
[DDMD] Use an alloc function for Token freelist instead of operator new.
  • Loading branch information
WalterBright committed Jul 25, 2014
2 parents f79c6c5 + d729564 commit b09c870
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/lexer.c
Expand Up @@ -70,17 +70,17 @@ static void cmtable_init()

const char *Token::tochars[TOKMAX];

void *Token::operator new(size_t size)
{ Token *t;

Token *Token::alloc()
{
if (Lexer::freelist)
{
t = Lexer::freelist;
Token *t = Lexer::freelist;
Lexer::freelist = t->next;
t->next = NULL;
return t;
}

return ::operator new(size);
return new Token();
}

#ifdef DEBUG
Expand Down Expand Up @@ -361,7 +361,7 @@ Token *Lexer::peek(Token *ct)
t = ct->next;
else
{
t = new Token();
t = Token::alloc();
scan(t);
ct->next = t;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lexer.h
Expand Up @@ -218,7 +218,7 @@ struct Token
};

static const char *tochars[TOKMAX];
static void *operator new(size_t sz);
static Token *alloc();

Token() : next(NULL) {}
int isKeyword();
Expand Down
2 changes: 1 addition & 1 deletion src/parse.c
Expand Up @@ -5253,7 +5253,7 @@ Statement *Parser::parseStatement(int flags, const utf8_t** endPtr)

default:
Ldefault:
*ptoklist = new Token();
*ptoklist = Token::alloc();
memcpy(*ptoklist, &token, sizeof(Token));
ptoklist = &(*ptoklist)->next;
*ptoklist = NULL;
Expand Down

0 comments on commit b09c870

Please sign in to comment.