[cfe-commits] r38757 - in /cfe/cfe/trunk: Lex/MacroExpander.cpp Lex/Preprocessor.cpp include/clang/Lex/MacroExpander.h
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:24:22 PDT 2007
Author: sabre
Date: Wed Jul 11 11:24:22 2007
New Revision: 38757
URL: http://llvm.org/viewvc/llvm-project?rev=38757&view=rev
Log:
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%.
Modified:
cfe/cfe/trunk/Lex/MacroExpander.cpp
cfe/cfe/trunk/Lex/Preprocessor.cpp
cfe/cfe/trunk/include/clang/Lex/MacroExpander.h
Modified: cfe/cfe/trunk/Lex/MacroExpander.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/MacroExpander.cpp?rev=38757&r1=38756&r2=38757&view=diff
==============================================================================
--- cfe/cfe/trunk/Lex/MacroExpander.cpp (original)
+++ cfe/cfe/trunk/Lex/MacroExpander.cpp Wed Jul 11 11:24:22 2007
@@ -26,12 +26,12 @@
/// 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 @@
// 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;
}
Modified: cfe/cfe/trunk/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/Preprocessor.cpp?rev=38757&r1=38756&r2=38757&view=diff
==============================================================================
--- cfe/cfe/trunk/Lex/Preprocessor.cpp (original)
+++ cfe/cfe/trunk/Lex/Preprocessor.cpp Wed Jul 11 11:24:22 2007
@@ -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 @@
--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 @@
}
}
- return MacroArgs::create(MI, ArgTokens);
+ return MacroArgs::create(MI, &ArgTokens[0], ArgTokens.size());
}
/// ComputeDATE_TIME - Compute the current time, enter it into the specified
Modified: cfe/cfe/trunk/include/clang/Lex/MacroExpander.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Lex/MacroExpander.h?rev=38757&r1=38756&r2=38757&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Lex/MacroExpander.h (original)
+++ cfe/cfe/trunk/include/clang/Lex/MacroExpander.h Wed Jul 11 11:24:22 2007
@@ -47,7 +47,8 @@
/// 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.
///
More information about the cfe-commits
mailing list