Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DDMD] Use an alloc function for Token freelist instead of operator new. #3808

Merged
merged 1 commit into from
Jul 25, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/lexer.c
Original file line number Diff line number Diff line change
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably either assign from a default constructed object or use placement new because it's not obvious that this should be kept in sync with the default constructor.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alloc doesn't have to initialize the memory properly. I just wanted to drop it out of the freelist completely.

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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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