diff options
author | Daniel Dunbar <daniel@zuster.org> | 2010-09-29 19:15:29 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2010-09-29 19:15:29 +0000 |
commit | 181ca5807467b95a3c7e701b44fc8100356d4a82 (patch) | |
tree | 6c77af5768c6b2fec6bf48ea302ea4a57e854b56 /clang/lib/Basic/Version.cpp | |
parent | 2c48dbec9628a5aa3a886cbce43fb3ace7e17bd1 (diff) | |
download | bcm5719-llvm-181ca5807467b95a3c7e701b44fc8100356d4a82.tar.gz bcm5719-llvm-181ca5807467b95a3c7e701b44fc8100356d4a82.zip |
Basic: Simplify getClangRepositoryPath and getClangRevision.
- I don't like returning StringRef's ever, unless it is actually important for
performance, which it isn't here.
- Also, stop validating getClangRevision to be an integer, I don't see a good
reason to do this.
llvm-svn: 115071
Diffstat (limited to 'clang/lib/Basic/Version.cpp')
-rw-r--r-- | clang/lib/Basic/Version.cpp | 43 |
1 files changed, 18 insertions, 25 deletions
diff --git a/clang/lib/Basic/Version.cpp b/clang/lib/Basic/Version.cpp index e9649e284d0..900b3e3859b 100644 --- a/clang/lib/Basic/Version.cpp +++ b/clang/lib/Basic/Version.cpp @@ -20,44 +20,37 @@ using namespace std; namespace clang { -llvm::StringRef getClangRepositoryPath() { +std::string getClangRepositoryPath() { #ifdef SVN_REPOSITORY - if (SVN_REPOSITORY[0] != '\0') { - static const char URL[] = SVN_REPOSITORY; - const char *URLEnd = URL + strlen(URL) - 1; + llvm::StringRef URL(SVN_REPOSITORY); +#else + llvm::StringRef URL(""); +#endif - // Strip off version from a build from an integration branch. - const char *End = strstr(URL, "/src/tools/clang"); - if (End) - URLEnd = End; + // Strip off version from a build from an integration branch. + URL = URL.slice(0, URL.find("/src/tools/clang")); - const char *Begin = strstr(URL, "cfe/"); - if (Begin) - return llvm::StringRef(Begin + 4, URLEnd - Begin - 4); + // Trim path prefix off, assuming path came from standard cfe path. + size_t Start = URL.find("cfe/"); + if (Start != llvm::StringRef::npos) + URL = URL.substr(Start + 4); - return llvm::StringRef(URL, URLEnd - URL); - } -#endif - return ""; + return URL; } -llvm::StringRef getClangRevision() { +std::string getClangRevision() { #ifdef SVN_REVISION - if (SVN_REVISION[0] != '\0') { - std::string revision; - llvm::raw_string_ostream OS(revision); - OS << strtol(SVN_REVISION, 0, 10); - return OS.str(); - } -#endif + return SVN_REVISION; +#else return ""; +#endif } std::string getClangFullRepositoryVersion() { std::string buf; llvm::raw_string_ostream OS(buf); - const llvm::StringRef &Path = getClangRepositoryPath(); - const llvm::StringRef &Revision = getClangRevision(); + std::string Path = getClangRepositoryPath(); + std::string Revision = getClangRevision(); if (!Path.empty()) OS << Path; if (!Revision.empty()) { |