aboutsummaryrefslogtreecommitdiff
path: root/Lex/MacroExpander.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-07-15 00:25:26 +0000
committerChris Lattner <sabre@nondot.org>2007-07-15 00:25:26 +0000
commit9594acf32de2939b15eafa8fe818607bfc56bf66 (patch)
tree7a6b83a0b4ddccddcd1c4e8de7d89edc09b0e39d /Lex/MacroExpander.cpp
parent9e344c65b1e8b83e1d3ada507cf653526ff2c005 (diff)
Cache macro expander objects to avoid thrashing malloc in heavy expansion situations.
This doesn't significantly improve carbon.h, but it does speed up INPUTS/macro_pounder_obj.c by 48% git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39864 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'Lex/MacroExpander.cpp')
-rw-r--r--Lex/MacroExpander.cpp41
1 files changed, 27 insertions, 14 deletions
diff --git a/Lex/MacroExpander.cpp b/Lex/MacroExpander.cpp
index 45d4611233..7a46b14297 100644
--- a/Lex/MacroExpander.cpp
+++ b/Lex/MacroExpander.cpp
@@ -233,13 +233,17 @@ const LexerToken &MacroArgs::getStringifiedArgument(unsigned ArgNo,
/// Create a macro expander for the specified macro with the specified actual
/// arguments. Note that this ctor takes ownership of the ActualArgs pointer.
-MacroExpander::MacroExpander(LexerToken &Tok, MacroArgs *Actuals,
- Preprocessor &pp)
- : Macro(Tok.getIdentifierInfo()->getMacroInfo()),
- ActualArgs(Actuals), PP(pp), CurToken(0),
- InstantiateLoc(Tok.getLocation()),
- AtStartOfLine(Tok.isAtStartOfLine()),
- HasLeadingSpace(Tok.hasLeadingSpace()) {
+void MacroExpander::Init(LexerToken &Tok, MacroArgs *Actuals) {
+ // If the client is reusing a macro expander, make sure to free any memory
+ // associated with it.
+ destroy();
+
+ Macro = Tok.getIdentifierInfo()->getMacroInfo();
+ ActualArgs = Actuals;
+ CurToken = 0;
+ InstantiateLoc = Tok.getLocation();
+ AtStartOfLine = Tok.isAtStartOfLine();
+ HasLeadingSpace = Tok.hasLeadingSpace();
MacroTokens = &*Macro->tokens_begin();
NumMacroTokens = Macro->tokens_end()-Macro->tokens_begin();
@@ -254,14 +258,23 @@ MacroExpander::MacroExpander(LexerToken &Tok, MacroArgs *Actuals,
Macro->DisableMacro();
}
+
+
/// Create a macro expander for the specified token stream. This does not
/// take ownership of the specified token vector.
-MacroExpander::MacroExpander(const LexerToken *TokArray, unsigned NumToks,
- Preprocessor &pp)
- : Macro(0), ActualArgs(0), PP(pp), MacroTokens(TokArray),
- NumMacroTokens(NumToks), CurToken(0),
- InstantiateLoc(SourceLocation()), AtStartOfLine(false),
- HasLeadingSpace(false) {
+void MacroExpander::Init(const LexerToken *TokArray, unsigned NumToks) {
+ // If the client is reusing a macro expander, make sure to free any memory
+ // associated with it.
+ destroy();
+
+ Macro = 0;
+ ActualArgs = 0;
+ MacroTokens = TokArray;
+ NumMacroTokens = NumToks;
+ CurToken = 0;
+ InstantiateLoc = SourceLocation();
+ AtStartOfLine = false;
+ HasLeadingSpace = false;
// Set HasLeadingSpace/AtStartOfLine so that the first token will be
// returned unmodified.
@@ -272,7 +285,7 @@ MacroExpander::MacroExpander(const LexerToken *TokArray, unsigned NumToks,
}
-MacroExpander::~MacroExpander() {
+void MacroExpander::destroy() {
// If this was a function-like macro that actually uses its arguments, delete
// the expanded tokens.
if (Macro && MacroTokens != &*Macro->tokens_begin())