summaryrefslogtreecommitdiffstats
path: root/clang/lib/Lex/PPDirectives.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-12-15 19:56:42 +0000
committerTed Kremenek <kremenek@apple.com>2008-12-15 19:56:42 +0000
commit6c7ea11300958d09908dc5b9aca6bd58acffef58 (patch)
treedf8fd9e4f36a9898d16c9c90b75c107e68b658f5 /clang/lib/Lex/PPDirectives.cpp
parent3cdf0a8a2e0e146c5cc8f5bcc5ef4e473d145b60 (diff)
downloadbcm5719-llvm-6c7ea11300958d09908dc5b9aca6bd58acffef58.tar.gz
bcm5719-llvm-6c7ea11300958d09908dc5b9aca6bd58acffef58.zip
Preprocessor: Allocate MacroInfo objects using a BumpPtrAllocator instead using new/delete. This speeds up -Eonly on Cocoa.h using the regular lexer by 1.8% and the PTHLexer by 3%.
llvm-svn: 61042
Diffstat (limited to 'clang/lib/Lex/PPDirectives.cpp')
-rw-r--r--clang/lib/Lex/PPDirectives.cpp26
1 files changed, 19 insertions, 7 deletions
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 0e4dc9f34e7..59df8255e32 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -22,6 +22,18 @@ using namespace clang;
// Utility Methods for Preprocessor Directive Handling.
//===----------------------------------------------------------------------===//
+MacroInfo* Preprocessor::AllocateMacroInfo(SourceLocation L) {
+ MacroInfo *MI;
+
+ if (!MICache.empty()) {
+ MI = MICache.back();
+ MICache.pop_back();
+ }
+ else MI = (MacroInfo*) BP.Allocate<MacroInfo>();
+ new (MI) MacroInfo(L);
+ return MI;
+}
+
/// DiscardUntilEndOfDirective - Read and discard all tokens remaining on the
/// current line until the tok::eom token is found.
void Preprocessor::DiscardUntilEndOfDirective() {
@@ -920,7 +932,7 @@ void Preprocessor::HandleDefineDirective(Token &DefineTok) {
if (CurLexer) CurLexer->SetCommentRetentionState(KeepMacroComments);
// Create the new macro.
- MacroInfo *MI = new MacroInfo(MacroNameTok.getLocation());
+ MacroInfo *MI = AllocateMacroInfo(MacroNameTok.getLocation());
Token Tok;
LexUnexpandedToken(Tok);
@@ -935,7 +947,7 @@ void Preprocessor::HandleDefineDirective(Token &DefineTok) {
MI->setIsFunctionLike();
if (ReadMacroDefinitionArgList(MI)) {
// Forget about MI.
- delete MI;
+ ReleaseMacroInfo(MI);
// Throw away the rest of the line.
if (CurPPLexer->ParsingPreprocessorDirective)
DiscardUntilEndOfDirective();
@@ -998,7 +1010,7 @@ void Preprocessor::HandleDefineDirective(Token &DefineTok) {
if (!Tok.getIdentifierInfo() ||
MI->getArgumentNum(Tok.getIdentifierInfo()) == -1) {
Diag(Tok, diag::err_pp_stringize_not_parameter);
- delete MI;
+ ReleaseMacroInfo(MI);
// Disable __VA_ARGS__ again.
Ident__VA_ARGS__->setIsPoisoned(true);
@@ -1023,12 +1035,12 @@ void Preprocessor::HandleDefineDirective(Token &DefineTok) {
if (NumTokens != 0) {
if (MI->getReplacementToken(0).is(tok::hashhash)) {
Diag(MI->getReplacementToken(0), diag::err_paste_at_start);
- delete MI;
+ ReleaseMacroInfo(MI);
return;
}
if (MI->getReplacementToken(NumTokens-1).is(tok::hashhash)) {
Diag(MI->getReplacementToken(NumTokens-1), diag::err_paste_at_end);
- delete MI;
+ ReleaseMacroInfo(MI);
return;
}
}
@@ -1051,7 +1063,7 @@ void Preprocessor::HandleDefineDirective(Token &DefineTok) {
<< MacroNameTok.getIdentifierInfo();
Diag(OtherMI->getDefinitionLoc(), diag::note_previous_definition);
}
- delete OtherMI;
+ ReleaseMacroInfo(OtherMI);
}
setMacroInfo(MacroNameTok.getIdentifierInfo(), MI);
@@ -1082,7 +1094,7 @@ void Preprocessor::HandleUndefDirective(Token &UndefTok) {
Diag(MI->getDefinitionLoc(), diag::pp_macro_not_used);
// Free macro definition.
- delete MI;
+ ReleaseMacroInfo(MI);
setMacroInfo(MacroNameTok.getIdentifierInfo(), 0);
}
OpenPOWER on IntegriCloud