]> granicus.if.org Git - clang/commitdiff
We don't need to place 0 in the URL string now that we return a StringRef.
authorBenjamin Kramer <benny.kra@googlemail.com>
Sat, 30 Jan 2010 14:01:39 +0000 (14:01 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Sat, 30 Jan 2010 14:01:39 +0000 (14:01 +0000)
- URL can go into read only memory now.
- Compilers will fold away all the strstr calls.

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

lib/Basic/Version.cpp

index fdb96e5732eb070d3c7684466b0464dd96053616..f9d62f9dc7c1ee2070fe1bd7f7c3404d42f34c4e 100644 (file)
@@ -21,27 +21,22 @@ using namespace std;
 namespace clang {
   
 llvm::StringRef getClangRepositoryPath() {
-  static const char *Path = 0;
-  if (Path)
-    return Path;
-  
-  static char URL[] = "$URL$";
-  char *End = strstr(URL, "/lib/Basic");
+  static const char URL[] = "$URL$";
+  const char *URLEnd = URL + strlen(URL);
+
+  const char *End = strstr(URL, "/lib/Basic");
   if (End)
-    *End = 0;
-  
+    URLEnd = End;
+
   End = strstr(URL, "/clang/tools/clang");
   if (End)
-    *End = 0;
-  
-  char *Begin = strstr(URL, "cfe/");
-  if (Begin) {
-    Path = Begin + 4;
-    return Path;
-  }
-  
-  Path = URL;
-  return Path;
+    URLEnd = End;
+
+  const char *Begin = strstr(URL, "cfe/");
+  if (Begin)
+    return llvm::StringRef(Begin + 4, URLEnd - Begin - 4);
+
+  return llvm::StringRef(URL, URLEnd - URL);
 }