make the token lexer allocate its temporary token buffers for
preexpanded macro arguments from the preprocessor's bump pointer.
This reduces # mallocs from 12444 to 11792.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66025 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Lex/TokenLexer.cpp b/lib/Lex/TokenLexer.cpp
index f0e2fbd..898b3a7 100644
--- a/lib/Lex/TokenLexer.cpp
+++ b/lib/Lex/TokenLexer.cpp
@@ -88,6 +88,7 @@
if (OwnsTokens) {
delete [] Tokens;
Tokens = 0;
+ OwnsTokens = false;
}
// TokenLexer owns its formal arguments.
@@ -264,13 +265,19 @@
// If anything changed, install this as the new Tokens list.
if (MadeChange) {
+ assert(!OwnsTokens && "This would leak if we already own the token list");
// This is deleted in the dtor.
NumTokens = ResultToks.size();
- Token *Res = new Token[ResultToks.size()];
+ llvm::BumpPtrAllocator &Alloc = PP.getPreprocessorAllocator();
+ Token *Res =
+ static_cast<Token *>(Alloc.Allocate(sizeof(Token)*ResultToks.size(),
+ llvm::alignof<Token>()));
if (NumTokens)
memcpy(Res, &ResultToks[0], NumTokens*sizeof(Token));
Tokens = Res;
- OwnsTokens = true;
+
+ // The preprocessor bump pointer owns these tokens, not us.
+ OwnsTokens = false;
}
}