[cfe-commits] r124760 - /cfe/trunk/lib/Basic/FileManager.cpp

Douglas Gregor dgregor at apple.com
Wed Feb 2 16:18:12 PST 2011


Author: dgregor
Date: Wed Feb  2 18:18:12 2011
New Revision: 124760

URL: http://llvm.org/viewvc/llvm-project?rev=124760&view=rev
Log:
Improve the performance of filename canonicalization by avoiding
redundant searches in the string. No functionality change.

Modified:
    cfe/trunk/lib/Basic/FileManager.cpp

Modified: cfe/trunk/lib/Basic/FileManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=124760&r1=124759&r2=124760&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/FileManager.cpp (original)
+++ cfe/trunk/lib/Basic/FileManager.cpp Wed Feb  2 18:18:12 2011
@@ -279,8 +279,8 @@
                                             llvm::SmallVectorImpl<char> &Scratch) {
   size_t Start = 0;
   bool Changed = false;
+  size_t FirstSlash = Filename.find('/', Start);
   do {
-    size_t FirstSlash = Filename.find('/', Start);
     if (FirstSlash == llvm::StringRef::npos) {
       // No more components. Just copy the rest of the file name, if
       // we need to.
@@ -302,6 +302,7 @@
       
       // Skip over the './'.
       Start = FirstSlash + 1;
+      FirstSlash = Filename.find('/', Start);
       continue;
     }
     
@@ -322,6 +323,7 @@
       
       // Skip over the 'foo/..'.
       Start = SecondSlash + 1;
+      FirstSlash = Filename.find('/', Start);
       continue;
     }
 
@@ -329,6 +331,11 @@
       Scratch.append(Filename.begin() + Start, 
                      Filename.begin() + FirstSlash + 1);
     Start = FirstSlash + 1;
+
+    if (SecondSlash == llvm::StringRef::npos)
+      FirstSlash = Filename.find('/', Start);
+    else
+      FirstSlash = SecondSlash;
   } while (true);
 
   if (Changed) {





More information about the cfe-commits mailing list