[cfe-commits] r40461 - in /cfe/trunk: Basic/SourceManager.cpp Driver/PrintPreprocessedOutput.cpp Lex/Lexer.cpp include/clang/Basic/SourceManager.h include/clang/Lex/Lexer.h

Chris Lattner sabre at nondot.org
Mon Jul 23 23:57:14 PDT 2007


Author: lattner
Date: Tue Jul 24 01:57:14 2007
New Revision: 40461

URL: http://llvm.org/viewvc/llvm-project?rev=40461&view=rev
Log:
Use a smallstring instead of an std::string in FileChanged to avoid some malloc traffic.

This speeds up -E on xalancbmk by 2.4%

Modified:
    cfe/trunk/Basic/SourceManager.cpp
    cfe/trunk/Driver/PrintPreprocessedOutput.cpp
    cfe/trunk/Lex/Lexer.cpp
    cfe/trunk/include/clang/Basic/SourceManager.h
    cfe/trunk/include/clang/Lex/Lexer.h

Modified: cfe/trunk/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Basic/SourceManager.cpp?rev=40461&r1=40460&r2=40461&view=diff

==============================================================================
--- cfe/trunk/Basic/SourceManager.cpp (original)
+++ cfe/trunk/Basic/SourceManager.cpp Tue Jul 24 01:57:14 2007
@@ -231,7 +231,7 @@
 /// getSourceName - This method returns the name of the file or buffer that
 /// the SourceLocation specifies.  This can be modified with #line directives,
 /// etc.
-std::string SourceManager::getSourceName(SourceLocation Loc) {
+const char *SourceManager::getSourceName(SourceLocation Loc) {
   unsigned FileID = Loc.getFileID();
   if (FileID == 0) return "";
   return getFileInfo(FileID)->Buffer->getBufferIdentifier();

Modified: cfe/trunk/Driver/PrintPreprocessedOutput.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/PrintPreprocessedOutput.cpp?rev=40461&r1=40460&r2=40461&view=diff

==============================================================================
--- cfe/trunk/Driver/PrintPreprocessedOutput.cpp (original)
+++ cfe/trunk/Driver/PrintPreprocessedOutput.cpp Tue Jul 24 01:57:14 2007
@@ -18,6 +18,7 @@
 #include "clang/Lex/Pragma.h"
 #include "clang/Basic/SourceManager.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Config/config.h"
 #include <cstdio>
@@ -123,13 +124,13 @@
 class PrintPPOutputPPCallbacks : public PPCallbacks {
   Preprocessor &PP;
   unsigned CurLine;
-  std::string CurFilename;
   bool EmittedTokensOnThisLine;
   DirectoryLookup::DirType FileType;
+  llvm::SmallString<512> CurFilename;
 public:
   PrintPPOutputPPCallbacks(Preprocessor &pp) : PP(pp) {
     CurLine = 0;
-    CurFilename = "<uninit>";
+    CurFilename += "<uninit>";
     EmittedTokensOnThisLine = false;
     FileType = DirectoryLookup::NormalHeaderDir;
   }
@@ -237,7 +238,9 @@
   
   Loc = SourceMgr.getLogicalLoc(Loc);
   CurLine = SourceMgr.getLineNumber(Loc);
-  CurFilename = Lexer::Stringify(SourceMgr.getSourceName(Loc));
+  CurFilename.clear();
+  CurFilename += SourceMgr.getSourceName(Loc);
+  Lexer::Stringify(CurFilename);
   FileType = FileType;
   
   if (EmittedTokensOnThisLine) {

Modified: cfe/trunk/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Lex/Lexer.cpp?rev=40461&r1=40460&r2=40461&view=diff

==============================================================================
--- cfe/trunk/Lex/Lexer.cpp (original)
+++ cfe/trunk/Lex/Lexer.cpp Tue Jul 24 01:57:14 2007
@@ -92,6 +92,17 @@
   return Result;
 }
 
+/// Stringify - Convert the specified string into a C string by escaping '\'
+/// and " characters.  This does not add surrounding ""'s to the string.
+void Lexer::Stringify(llvm::SmallVectorImpl<char> &Str) {
+  for (unsigned i = 0, e = Str.size(); i != e; ++i) {
+    if (Str[i] == '\\' || Str[i] == '"') {
+      Str.insert(Str.begin()+i, '\\');
+      ++i; ++e;
+    }
+  }
+}
+
 
 //===----------------------------------------------------------------------===//
 // Character information.

Modified: cfe/trunk/include/clang/Basic/SourceManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManager.h?rev=40461&r1=40460&r2=40461&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManager.h Tue Jul 24 01:57:14 2007
@@ -240,7 +240,7 @@
   /// getSourceName - This method returns the name of the file or buffer that
   /// the SourceLocation specifies.  This can be modified with #line directives,
   /// etc.
-  std::string getSourceName(SourceLocation Loc);
+  const char *getSourceName(SourceLocation Loc);
 
   /// Given a SourceLocation object, return the logical location referenced by
   /// the ID.  This logical location is subject to #line directives, etc.

Modified: cfe/trunk/include/clang/Lex/Lexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Lexer.h?rev=40461&r1=40460&r2=40461&view=diff

==============================================================================
--- cfe/trunk/include/clang/Lex/Lexer.h (original)
+++ cfe/trunk/include/clang/Lex/Lexer.h Tue Jul 24 01:57:14 2007
@@ -17,6 +17,7 @@
 #include "clang/Lex/Token.h"
 #include "clang/Lex/MultipleIncludeOpt.h"
 #include "clang/Basic/LangOptions.h"
+#include "llvm/ADT/SmallVector.h"
 #include <string>
 #include <vector>
 #include <cassert>
@@ -173,6 +174,10 @@
   /// If Charify is true, this escapes the ' character instead of ".
   static std::string Stringify(const std::string &Str, bool Charify = false);
   
+  /// Stringify - Convert the specified string into a C string by escaping '\'
+  /// and " characters.  This does not add surrounding ""'s to the string.
+  static void Stringify(llvm::SmallVectorImpl<char> &Str);
+  
   //===--------------------------------------------------------------------===//
   // Internal implementation interfaces.
 private:





More information about the cfe-commits mailing list