diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2010-01-30 14:01:39 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2010-01-30 14:01:39 +0000 |
commit | e242d5f5fae8b16cb2d54b9dbb60855d4c67e67d (patch) | |
tree | c772d67509c9564ec3c0b53eeaf404021f39ab78 /lib/Basic/Version.cpp | |
parent | 09f52a696e97d5efc933ed413ddb01d8c537417c (diff) |
We don't need to place 0 in the URL string now that we return a StringRef.
- 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
Diffstat (limited to 'lib/Basic/Version.cpp')
-rw-r--r-- | lib/Basic/Version.cpp | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/lib/Basic/Version.cpp b/lib/Basic/Version.cpp index fdb96e5732..f9d62f9dc7 100644 --- a/lib/Basic/Version.cpp +++ b/lib/Basic/Version.cpp @@ -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); } |