summaryrefslogtreecommitdiffstats
path: root/clang/tools
diff options
context:
space:
mode:
authorDavid Blaikie <dblaikie@gmail.com>2014-10-16 17:23:58 +0000
committerDavid Blaikie <dblaikie@gmail.com>2014-10-16 17:23:58 +0000
commit92c8c95943269de3a06c449573a9b3e432881e90 (patch)
treec9b33e5ddf748a2dc49cd7e87908c7ed9e015a48 /clang/tools
parent74246aaf89fc596dd018c63365d894d0fc4abe42 (diff)
downloadbcm5719-llvm-92c8c95943269de3a06c449573a9b3e432881e90.tar.gz
bcm5719-llvm-92c8c95943269de3a06c449573a9b3e432881e90.zip
Use iterators and algorithms to possibly make this code a bit tidier
(also, the code executed once the element was found was split half inside the loop and half after it - now put it all together after the find operation) I'm a bit concerned that this code is rather untested (commenting out this whole function and running check-clang doesn't fail any tests)... And I wish I had polymorphic lambdas. llvm-svn: 219938
Diffstat (limited to 'clang/tools')
-rw-r--r--clang/tools/driver/driver.cpp28
1 files changed, 12 insertions, 16 deletions
diff --git a/clang/tools/driver/driver.cpp b/clang/tools/driver/driver.cpp
index 3e98b2c6c95..b7f7fbf851c 100644
--- a/clang/tools/driver/driver.cpp
+++ b/clang/tools/driver/driver.cpp
@@ -243,24 +243,20 @@ static void ParseProgName(SmallVectorImpl<const char *> &ArgVector,
StringRef Prefix;
for (int Components = 2; Components; --Components) {
- bool FoundMatch = false;
- size_t i;
-
- for (i = 0; i < llvm::array_lengthof(suffixes); ++i) {
- if (ProgNameRef.endswith(suffixes[i].Suffix)) {
- FoundMatch = true;
- SmallVectorImpl<const char *>::iterator it = ArgVector.begin();
+ auto I = std::find_if(std::begin(suffixes), std::end(suffixes),
+ [&](const decltype(suffixes[0]) &suffix) {
+ return ProgNameRef.endswith(suffix.Suffix);
+ });
+
+ if (I != std::end(suffixes)) {
+ if (I->ModeFlag) {
+ auto it = ArgVector.begin();
if (it != ArgVector.end())
++it;
- if (suffixes[i].ModeFlag)
- ArgVector.insert(it, suffixes[i].ModeFlag);
- break;
+ ArgVector.insert(it, I->ModeFlag);
}
- }
-
- if (FoundMatch) {
StringRef::size_type LastComponent = ProgNameRef.rfind('-',
- ProgNameRef.size() - strlen(suffixes[i].Suffix));
+ ProgNameRef.size() - strlen(I->Suffix));
if (LastComponent != StringRef::npos)
Prefix = ProgNameRef.slice(0, LastComponent);
break;
@@ -277,13 +273,13 @@ static void ParseProgName(SmallVectorImpl<const char *> &ArgVector,
std::string IgnoredError;
if (llvm::TargetRegistry::lookupTarget(Prefix, IgnoredError)) {
- SmallVectorImpl<const char *>::iterator it = ArgVector.begin();
+ auto it = ArgVector.begin();
if (it != ArgVector.end())
++it;
const char* Strings[] =
{ GetStableCStr(SavedStrings, std::string("-target")),
GetStableCStr(SavedStrings, Prefix) };
- ArgVector.insert(it, Strings, Strings + llvm::array_lengthof(Strings));
+ ArgVector.insert(it, std::begin(Strings), std::end(Strings));
}
}
OpenPOWER on IntegriCloud