r243970 - [FileManager] Use StringRef::copy to store canonical paths.

Benjamin Kramer benny.kra at googlemail.com
Tue Aug 4 04:27:08 PDT 2015


Author: d0k
Date: Tue Aug  4 06:27:08 2015
New Revision: 243970

URL: http://llvm.org/viewvc/llvm-project?rev=243970&view=rev
Log:
[FileManager] Use StringRef::copy to store canonical paths.

No functional change intended.

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=243970&r1=243969&r2=243970&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/FileManager.cpp (original)
+++ cfe/trunk/lib/Basic/FileManager.cpp Tue Aug  4 06:27:08 2015
@@ -570,12 +570,8 @@ StringRef FileManager::getCanonicalName(
 
 #ifdef LLVM_ON_UNIX
   char CanonicalNameBuf[PATH_MAX];
-  if (realpath(Dir->getName(), CanonicalNameBuf)) {
-    unsigned Len = strlen(CanonicalNameBuf);
-    char *Mem = static_cast<char *>(CanonicalNameStorage.Allocate(Len, 1));
-    memcpy(Mem, CanonicalNameBuf, Len);
-    CanonicalName = StringRef(Mem, Len);
-  }
+  if (realpath(Dir->getName(), CanonicalNameBuf))
+    CanonicalName = StringRef(CanonicalNameBuf).copy(CanonicalNameStorage);
 #else
   SmallString<256> CanonicalNameBuf(CanonicalName);
   llvm::sys::fs::make_absolute(CanonicalNameBuf);
@@ -587,9 +583,7 @@ StringRef FileManager::getCanonicalName(
   // Ideally we'd have an equivalent of `realpath` and could implement
   // sys::fs::canonical across all the platforms.
   removeDotPaths(CanonicalNameBuf, /*RemoveDotDot*/true);
-  char *Mem = CanonicalNameStorage.Allocate<char>(CanonicalNameBuf.size());
-  memcpy(Mem, CanonicalNameBuf.data(), CanonicalNameBuf.size());
-  CanonicalName = StringRef(Mem, CanonicalNameBuf.size());
+  CanonicalName = StringRef(CanonicalNameBuf).copy(CanonicalNameStorage);
 #endif
 
   CanonicalDirNames.insert(std::make_pair(Dir, CanonicalName));





More information about the cfe-commits mailing list