summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-07-26 06:26:52 +0000
committerChris Lattner <sabre@nondot.org>2006-07-26 06:26:52 +0000
commit7a4af3b73ddb9dc9dfc5441a51b64bcad588ea74 (patch)
treed1d3258e30fbc5aabd81e8d9047f9b7f3c74b27d /clang
parentc1410dc1e616841a8483a4849ecdc664df0d7219 (diff)
downloadbcm5719-llvm-7a4af3b73ddb9dc9dfc5441a51b64bcad588ea74.tar.gz
bcm5719-llvm-7a4af3b73ddb9dc9dfc5441a51b64bcad588ea74.zip
Change Preprocessor::ReadFunctionLikeMacroArgs to use a SmallVector to lex
argument tokens into instead of a real vector. This avoids some malloc traffic in common cases. In an "abusive macro expansion" testcase, this reduced -Eonly time by 25%. llvm-svn: 38757
Diffstat (limited to 'clang')
-rw-r--r--clang/Lex/MacroExpander.cpp6
-rw-r--r--clang/Lex/Preprocessor.cpp8
-rw-r--r--clang/include/clang/Lex/MacroExpander.h3
3 files changed, 10 insertions, 7 deletions
diff --git a/clang/Lex/MacroExpander.cpp b/clang/Lex/MacroExpander.cpp
index 24aab614c8a..8fb569afd37 100644
--- a/clang/Lex/MacroExpander.cpp
+++ b/clang/Lex/MacroExpander.cpp
@@ -26,12 +26,12 @@ using namespace clang;
/// MacroArgs ctor function - This destroys the vector passed in.
MacroArgs *MacroArgs::create(const MacroInfo *MI,
- const std::vector<LexerToken> &UnexpArgTokens) {
+ const LexerToken *UnexpArgTokens,
+ unsigned NumToks) {
assert(MI->isFunctionLike() &&
"Can't have args for an object-like macro!");
// Allocate memory for the MacroArgs object with the lexer tokens at the end.
- unsigned NumToks = UnexpArgTokens.size();
MacroArgs *Result = (MacroArgs*)malloc(sizeof(MacroArgs) +
NumToks*sizeof(LexerToken));
// Construct the macroargs object.
@@ -40,7 +40,7 @@ MacroArgs *MacroArgs::create(const MacroInfo *MI,
// Copy the actual unexpanded tokens to immediately after the result ptr.
if (NumToks)
memcpy(const_cast<LexerToken*>(Result->getUnexpArgument(0)),
- &UnexpArgTokens[0], NumToks*sizeof(LexerToken));
+ UnexpArgTokens, NumToks*sizeof(LexerToken));
return Result;
}
diff --git a/clang/Lex/Preprocessor.cpp b/clang/Lex/Preprocessor.cpp
index 71f315d03d8..1a95b887f39 100644
--- a/clang/Lex/Preprocessor.cpp
+++ b/clang/Lex/Preprocessor.cpp
@@ -33,6 +33,7 @@
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/SourceManager.h"
+#include "llvm/ADT/SmallVector.h"
#include <iostream>
using namespace llvm;
using namespace clang;
@@ -709,8 +710,9 @@ MacroArgs *Preprocessor::ReadFunctionLikeMacroArgs(LexerToken &MacroName,
--NumFixedArgsLeft; // Start reading the first arg.
// ArgTokens - Build up a list of tokens that make up each argument. Each
- // argument is separated by an EOF token.
- std::vector<LexerToken> ArgTokens;
+ // argument is separated by an EOF token. Use a SmallVector so we can avoid
+ // heap allocations in the common case.
+ SmallVector<LexerToken, 64> ArgTokens;
unsigned NumActuals = 0;
while (Tok.getKind() == tok::comma) {
@@ -808,7 +810,7 @@ MacroArgs *Preprocessor::ReadFunctionLikeMacroArgs(LexerToken &MacroName,
}
}
- return MacroArgs::create(MI, ArgTokens);
+ return MacroArgs::create(MI, &ArgTokens[0], ArgTokens.size());
}
/// ComputeDATE_TIME - Compute the current time, enter it into the specified
diff --git a/clang/include/clang/Lex/MacroExpander.h b/clang/include/clang/Lex/MacroExpander.h
index c001182d258..f5f802a0d68 100644
--- a/clang/include/clang/Lex/MacroExpander.h
+++ b/clang/include/clang/Lex/MacroExpander.h
@@ -47,7 +47,8 @@ public:
/// MacroArgs ctor function - Create a new MacroArgs object with the specified
/// macro and argument info.
static MacroArgs *create(const MacroInfo *MI,
- const std::vector<LexerToken> &UnexpArgTokens);
+ const LexerToken *UnexpArgTokens,
+ unsigned NumArgTokens);
/// destroy - Destroy and deallocate the memory for this object.
///
OpenPOWER on IntegriCloud