]> granicus.if.org Git - clang/commitdiff
Use a smallstring instead of an std::string in FileChanged to avoid some malloc traffic.
authorChris Lattner <sabre@nondot.org>
Tue, 24 Jul 2007 06:57:14 +0000 (06:57 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 24 Jul 2007 06:57:14 +0000 (06:57 +0000)
This speeds up -E on xalancbmk by 2.4%

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40461 91177308-0d34-0410-b5e6-96231b3b80d8

Basic/SourceManager.cpp
Driver/PrintPreprocessedOutput.cpp
Lex/Lexer.cpp
include/clang/Basic/SourceManager.h
include/clang/Lex/Lexer.h

index e53547087df01bb49932a078c96a60819cbcc8d3..df13fad37c3162ddfd4f605054f6737d3d9ddfa2 100644 (file)
@@ -231,7 +231,7 @@ unsigned SourceManager::getColumnNumber(SourceLocation Loc) const {
 /// 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();
index d5c5b9a08bb3447fae7447cc6430a662ba2e8739..a8bc4e40d222dde426682a55f6bd8116b6dd918a 100644 (file)
@@ -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 @@ namespace {
 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 @@ void PrintPPOutputPPCallbacks::FileChanged(SourceLocation Loc,
   
   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) {
index f23d34ed422f7aa48889cf841b4446f26d5c2f1c..c45a36a9a59fbca0b6c209d421cc435774fdc31c 100644 (file)
@@ -92,6 +92,17 @@ std::string Lexer::Stringify(const std::string &Str, bool Charify) {
   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.
index dd8a86cc7e986de6f985010c0ba7f7388022f7d3..825e7dee65ab175588c51df3fd8ba17d13660d33 100644 (file)
@@ -240,7 +240,7 @@ public:
   /// 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.
index 6cff00020784a8017bd4397827377d041d846832..18c2fca31aac1ce5d457225b1920226b08d9721d 100644 (file)
@@ -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 @@ public:
   /// 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: