[cfe-commits] r38758 - /cfe/cfe/trunk/Lex/MacroExpander.cpp

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:24:23 PDT 2007


Author: sabre
Date: Wed Jul 11 11:24:23 2007
New Revision: 38758

URL: http://llvm.org/viewvc/llvm-project?rev=38758&view=rev
Log:
Switch ExpandFunctionArguments to use a smallvector instead of a vector,
speeding up my macro expansion torture test from .75s to .5s (33%!)

Modified:
    cfe/cfe/trunk/Lex/MacroExpander.cpp

Modified: cfe/cfe/trunk/Lex/MacroExpander.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/MacroExpander.cpp?rev=38758&r1=38757&r2=38758&view=diff

==============================================================================
--- cfe/cfe/trunk/Lex/MacroExpander.cpp (original)
+++ cfe/cfe/trunk/Lex/MacroExpander.cpp Wed Jul 11 11:24:23 2007
@@ -16,6 +16,7 @@
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/Diagnostic.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/Config/Alloca.h"
 using namespace llvm;
 using namespace clang;
@@ -285,7 +286,7 @@
 /// Expand the arguments of a function-like macro so that we can quickly
 /// return preexpanded tokens from MacroTokens.
 void MacroExpander::ExpandFunctionArguments() {
-  std::vector<LexerToken> ResultToks;
+  SmallVector<LexerToken, 128> ResultToks;
   
   // Loop through the MacroTokens tokens, expanding them into ResultToks.  Keep
   // track of whether we change anything.  If not, no need to keep them.  If so,
@@ -354,8 +355,7 @@
         if (ResultArgToks->getKind() != tok::eof) {
           unsigned FirstResult = ResultToks.size();
           unsigned NumToks = MacroArgs::getArgLength(ResultArgToks);
-          ResultToks.insert(ResultToks.end(), ResultArgToks, 
-                            ResultArgToks+NumToks);
+          ResultToks.append(ResultArgToks, ResultArgToks+NumToks);
         
           // If any tokens were substituted from the argument, the whitespace
           // before the first token should match the whitespace of the arg
@@ -372,7 +372,7 @@
 
       unsigned NumToks = MacroArgs::getArgLength(ArgToks);
       if (NumToks) {  // Not an empty argument?
-        ResultToks.insert(ResultToks.end(), ArgToks, ArgToks+NumToks);
+        ResultToks.append(ArgToks, ArgToks+NumToks);
         continue;
       }
       





More information about the cfe-commits mailing list