diff options
| author | Chris Lattner <sabre@nondot.org> | 2009-03-04 06:50:57 +0000 | 
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2009-03-04 06:50:57 +0000 | 
| commit | 8322dc809e2e1c8477c68eb5e778e2646c8faf8e (patch) | |
| tree | 39e50152c54e4736748ac0468c8f5cd3ee65669c /clang/lib | |
| parent | 9edd616b5945bfd778d078a15fb4e4000a7e6ba3 (diff) | |
| download | bcm5719-llvm-8322dc809e2e1c8477c68eb5e778e2646c8faf8e.tar.gz bcm5719-llvm-8322dc809e2e1c8477c68eb5e778e2646c8faf8e.zip  | |
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.
llvm-svn: 66025
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Lex/TokenLexer.cpp | 11 | 
1 files changed, 9 insertions, 2 deletions
diff --git a/clang/lib/Lex/TokenLexer.cpp b/clang/lib/Lex/TokenLexer.cpp index f0e2fbdfa62..898b3a780dd 100644 --- a/clang/lib/Lex/TokenLexer.cpp +++ b/clang/lib/Lex/TokenLexer.cpp @@ -88,6 +88,7 @@ void TokenLexer::destroy() {    if (OwnsTokens) {      delete [] Tokens;      Tokens = 0; +    OwnsTokens = false;    }    // TokenLexer owns its formal arguments. @@ -264,13 +265,19 @@ void TokenLexer::ExpandFunctionArguments() {    // 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;    }  }  | 

