[clang-tidy][NFC] Use moves instead of copies when constructing OptionsProviders.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D92267
This commit is contained in:
Nathan James 2020-12-10 11:34:57 +00:00
parent 958608285e
commit bedf3a0f50
No known key found for this signature in database
GPG Key ID: CC007AFCDA90AA5F
3 changed files with 55 additions and 57 deletions

View File

@ -195,14 +195,13 @@ DefaultOptionsProvider::getRawOptions(llvm::StringRef FileName) {
}
ConfigOptionsProvider::ConfigOptionsProvider(
const ClangTidyGlobalOptions &GlobalOptions,
const ClangTidyOptions &DefaultOptions,
const ClangTidyOptions &ConfigOptions,
const ClangTidyOptions &OverrideOptions,
ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions,
ClangTidyOptions ConfigOptions, ClangTidyOptions OverrideOptions,
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS)
: FileOptionsBaseProvider(GlobalOptions, DefaultOptions, OverrideOptions,
FS),
ConfigOptions(ConfigOptions) {}
: FileOptionsBaseProvider(std::move(GlobalOptions),
std::move(DefaultOptions),
std::move(OverrideOptions), std::move(FS)),
ConfigOptions(std::move(ConfigOptions)) {}
std::vector<OptionsSource>
ConfigOptionsProvider::getRawOptions(llvm::StringRef FileName) {
@ -227,24 +226,25 @@ ConfigOptionsProvider::getRawOptions(llvm::StringRef FileName) {
}
FileOptionsBaseProvider::FileOptionsBaseProvider(
const ClangTidyGlobalOptions &GlobalOptions,
const ClangTidyOptions &DefaultOptions,
const ClangTidyOptions &OverrideOptions,
ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions,
ClangTidyOptions OverrideOptions,
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS)
: DefaultOptionsProvider(GlobalOptions, DefaultOptions),
OverrideOptions(OverrideOptions), FS(std::move(VFS)) {
: DefaultOptionsProvider(std::move(GlobalOptions),
std::move(DefaultOptions)),
OverrideOptions(std::move(OverrideOptions)), FS(std::move(VFS)) {
if (!FS)
FS = llvm::vfs::getRealFileSystem();
ConfigHandlers.emplace_back(".clang-tidy", parseConfiguration);
}
FileOptionsBaseProvider::FileOptionsBaseProvider(
const ClangTidyGlobalOptions &GlobalOptions,
const ClangTidyOptions &DefaultOptions,
const ClangTidyOptions &OverrideOptions,
const FileOptionsBaseProvider::ConfigFileHandlers &ConfigHandlers)
: DefaultOptionsProvider(GlobalOptions, DefaultOptions),
OverrideOptions(OverrideOptions), ConfigHandlers(ConfigHandlers) {}
ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions,
ClangTidyOptions OverrideOptions,
FileOptionsBaseProvider::ConfigFileHandlers ConfigHandlers)
: DefaultOptionsProvider(std::move(GlobalOptions),
std::move(DefaultOptions)),
OverrideOptions(std::move(OverrideOptions)),
ConfigHandlers(std::move(ConfigHandlers)) {}
void FileOptionsBaseProvider::addRawFileOptions(
llvm::StringRef AbsolutePath, std::vector<OptionsSource> &CurOptions) {
@ -286,20 +286,20 @@ void FileOptionsBaseProvider::addRawFileOptions(
}
FileOptionsProvider::FileOptionsProvider(
const ClangTidyGlobalOptions &GlobalOptions,
const ClangTidyOptions &DefaultOptions,
const ClangTidyOptions &OverrideOptions,
ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions,
ClangTidyOptions OverrideOptions,
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS)
: FileOptionsBaseProvider(GlobalOptions, DefaultOptions, OverrideOptions,
VFS){}
: FileOptionsBaseProvider(std::move(GlobalOptions),
std::move(DefaultOptions),
std::move(OverrideOptions), std::move(VFS)) {}
FileOptionsProvider::FileOptionsProvider(
const ClangTidyGlobalOptions &GlobalOptions,
const ClangTidyOptions &DefaultOptions,
const ClangTidyOptions &OverrideOptions,
const FileOptionsBaseProvider::ConfigFileHandlers &ConfigHandlers)
: FileOptionsBaseProvider(GlobalOptions, DefaultOptions, OverrideOptions,
ConfigHandlers) {}
ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions,
ClangTidyOptions OverrideOptions,
FileOptionsBaseProvider::ConfigFileHandlers ConfigHandlers)
: FileOptionsBaseProvider(
std::move(GlobalOptions), std::move(DefaultOptions),
std::move(OverrideOptions), std::move(ConfigHandlers)) {}
// FIXME: This method has some common logic with clang::format::getStyle().
// Consider pulling out common bits to a findParentFileWithName function or

View File

@ -173,9 +173,10 @@ public:
/// returns the same options for all files.
class DefaultOptionsProvider : public ClangTidyOptionsProvider {
public:
DefaultOptionsProvider(const ClangTidyGlobalOptions &GlobalOptions,
const ClangTidyOptions &Options)
: GlobalOptions(GlobalOptions), DefaultOptions(Options) {}
DefaultOptionsProvider(ClangTidyGlobalOptions GlobalOptions,
ClangTidyOptions Options)
: GlobalOptions(std::move(GlobalOptions)),
DefaultOptions(std::move(Options)) {}
const ClangTidyGlobalOptions &getGlobalOptions() override {
return GlobalOptions;
}
@ -187,7 +188,7 @@ private:
};
class FileOptionsBaseProvider : public DefaultOptionsProvider {
public:
protected:
// A pair of configuration file base name and a function parsing
// configuration from text in the corresponding format.
typedef std::pair<std::string, std::function<llvm::ErrorOr<ClangTidyOptions>(
@ -213,16 +214,15 @@ public:
/// take precedence over ".clang-tidy" if both reside in the same directory.
typedef std::vector<ConfigFileHandler> ConfigFileHandlers;
FileOptionsBaseProvider(
const ClangTidyGlobalOptions &GlobalOptions,
const ClangTidyOptions &DefaultOptions,
const ClangTidyOptions &OverrideOptions,
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS = nullptr);
FileOptionsBaseProvider(ClangTidyGlobalOptions GlobalOptions,
ClangTidyOptions DefaultOptions,
ClangTidyOptions OverrideOptions,
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS);
FileOptionsBaseProvider(const ClangTidyGlobalOptions &GlobalOptions,
const ClangTidyOptions &DefaultOptions,
const ClangTidyOptions &OverrideOptions,
const ConfigFileHandlers &ConfigHandlers);
FileOptionsBaseProvider(ClangTidyGlobalOptions GlobalOptions,
ClangTidyOptions DefaultOptions,
ClangTidyOptions OverrideOptions,
ConfigFileHandlers ConfigHandlers);
protected:
void addRawFileOptions(llvm::StringRef AbsolutePath,
@ -243,10 +243,8 @@ protected:
class ConfigOptionsProvider : public FileOptionsBaseProvider {
public:
ConfigOptionsProvider(
const ClangTidyGlobalOptions &GlobalOptions,
const ClangTidyOptions &DefaultOptions,
const ClangTidyOptions &ConfigOptions,
const ClangTidyOptions &OverrideOptions,
ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions,
ClangTidyOptions ConfigOptions, ClangTidyOptions OverrideOptions,
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS = nullptr);
std::vector<OptionsSource> getRawOptions(llvm::StringRef FileName) override;
@ -275,9 +273,8 @@ public:
/// If any of the \param OverrideOptions fields are set, they will override
/// whatever options are read from the configuration file.
FileOptionsProvider(
const ClangTidyGlobalOptions &GlobalOptions,
const ClangTidyOptions &DefaultOptions,
const ClangTidyOptions &OverrideOptions,
ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions,
ClangTidyOptions OverrideOptions,
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS = nullptr);
/// Initializes the \c FileOptionsProvider instance with a custom set
@ -297,10 +294,10 @@ public:
/// that can parse configuration from this file type. The configuration files
/// in each directory are searched for in the order of appearance in
/// \p ConfigHandlers.
FileOptionsProvider(const ClangTidyGlobalOptions &GlobalOptions,
const ClangTidyOptions &DefaultOptions,
const ClangTidyOptions &OverrideOptions,
const ConfigFileHandlers &ConfigHandlers);
FileOptionsProvider(ClangTidyGlobalOptions GlobalOptions,
ClangTidyOptions DefaultOptions,
ClangTidyOptions OverrideOptions,
ConfigFileHandlers ConfigHandlers);
std::vector<OptionsSource> getRawOptions(llvm::StringRef FileName) override;
};

View File

@ -318,9 +318,9 @@ static std::unique_ptr<ClangTidyOptionsProvider> createOptionsProvider(
parseConfiguration(Configuration);
if (ParsedConfig)
return std::make_unique<ConfigOptionsProvider>(
GlobalOptions,
std::move(GlobalOptions),
ClangTidyOptions::getDefaults().merge(DefaultOptions, 0),
*ParsedConfig, OverrideOptions, std::move(FS));
std::move(*ParsedConfig), std::move(OverrideOptions), std::move(FS));
llvm::errs() << "Error: invalid configuration specified.\n"
<< ParsedConfig.getError().message() << "\n";
return nullptr;
@ -347,8 +347,9 @@ static std::unique_ptr<ClangTidyOptionsProvider> createOptionsProvider(
if (Config.getNumOccurrences() > 0)
return LoadConfig(Config);
return std::make_unique<FileOptionsProvider>(GlobalOptions, DefaultOptions,
OverrideOptions, std::move(FS));
return std::make_unique<FileOptionsProvider>(
std::move(GlobalOptions), std::move(DefaultOptions),
std::move(OverrideOptions), std::move(FS));
}
llvm::IntrusiveRefCntPtr<vfs::FileSystem>