From 8acb5f2723ecaf0f1904a085ad79d0623cec38f6 Mon Sep 17 00:00:00 2001 From: Nathan James Date: Tue, 15 Dec 2020 16:19:12 +0000 Subject: [PATCH] [clang][driver][NFC] Use StringRef instead of std::string --- clang/lib/Driver/Driver.cpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 5e4eb8c..dc9ec1b 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -779,10 +779,9 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C, /// by Dirs. /// static bool searchForFile(SmallVectorImpl &FilePath, - ArrayRef Dirs, - StringRef FileName) { + ArrayRef Dirs, StringRef FileName) { SmallString<128> WPath; - for (const std::string &Dir : Dirs) { + for (const StringRef &Dir : Dirs) { if (Dir.empty()) continue; WPath.clear(); @@ -807,7 +806,7 @@ bool Driver::readConfigFile(StringRef FileName) { // Read options from config file. llvm::SmallString<128> CfgFileName(FileName); llvm::sys::path::native(CfgFileName); - ConfigFile = std::string(CfgFileName.str()); + ConfigFile = std::string(CfgFileName); bool ContainErrors; CfgOptions = std::make_unique( ParseArgStrings(NewCfgArgs, IsCLMode(), ContainErrors)); @@ -864,9 +863,10 @@ bool Driver::loadConfigFile() { std::vector ConfigFiles = CLOptions->getAllArgValues(options::OPT_config); if (ConfigFiles.size() > 1) { - if (!std::all_of( - ConfigFiles.begin(), ConfigFiles.end(), - [ConfigFiles](std::string s) { return s == ConfigFiles[0]; })) { + if (!std::all_of(ConfigFiles.begin(), ConfigFiles.end(), + [ConfigFiles](const std::string &s) { + return s == ConfigFiles[0]; + })) { Diag(diag::err_drv_duplicate_config); return true; } @@ -939,10 +939,7 @@ bool Driver::loadConfigFile() { } // Prepare list of directories where config file is searched for. - SmallVector CfgFileSearchDirs; - CfgFileSearchDirs.push_back(UserConfigDir); - CfgFileSearchDirs.push_back(SystemConfigDir); - CfgFileSearchDirs.push_back(Dir); + StringRef CfgFileSearchDirs[] = {UserConfigDir, SystemConfigDir, Dir}; // Try to find config file. First try file with corrected architecture. llvm::SmallString<128> CfgFilePath; @@ -973,7 +970,7 @@ bool Driver::loadConfigFile() { // --config. If it was deduced from executable name, it is not an error. if (FileSpecifiedExplicitly) { Diag(diag::err_drv_config_file_not_found) << CfgFileName; - for (const std::string &SearchDir : CfgFileSearchDirs) + for (const StringRef &SearchDir : CfgFileSearchDirs) if (!SearchDir.empty()) Diag(diag::note_drv_config_file_searched_in) << SearchDir; return true; -- 2.7.4