This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by njames93 on Nov 28 2020, 5:33 AM.

Diff Detail

Event Timeline

njames93 created this revision.Nov 28 2020, 5:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 28 2020, 5:33 AM
njames93 requested review of this revision.Nov 28 2020, 5:33 AM
Quuxplusone added inline comments.
clang-tools-extra/clang-tidy/ClangTidyOptions.h
176–179

If you're refactoring ctors anyway, perhaps add explicit to all of them? (The only reason to have a non-explicit ctor is if you want to enable callers to write DefaultOptionsProvider d = {gopt, opt}; instead of auto d = DefaultOptionsProvider(gopt, opt);.) But this would be scope creep, of course.

225

I'd strongly recommend doing these two signatures in exactly the same way as you've done the others: pass by value and std::move out of it. Pass-by-rvalue-reference should be reserved for arcane stuff like hand-written move-constructors. You don't need pass-by-rvalue-reference here.

njames93 added inline comments.Nov 28 2020, 8:18 AM
clang-tools-extra/clang-tidy/ClangTidyOptions.h
176–179

explicit/non-explicit doesn't really affect much here. These constructors are only used for constructing base classes or forwarding args to std::make_unique.

225

While I agree that rvalues in constructors is usually suspicious, in this case it does make sense.
Firstly, FileOptionsBaseProviders constructors aren't exposed to the public interface, so we don't really need to worry on that front.
Using r-values saves unneeded move constructor calls, which given that ClangTidyGlobalOptions and ClangTidyOptions have non-trivial most constructors, this is a slight win.
Is it still better to just pass by value though??

clang-tools-extra/clang-tidy/ClangTidyOptions.h
225

Well, IMHO it's better to just pass by value (for clarity). But it doesn't matter much either way. IMHO the "performance" angle doesn't matter because optimizing compilers, so basically at this point we're trading off "code clarity" versus "amount of bikeshedding in this PR," and I'm certainly willing to stop my bikeshedding, either way. :)

njames93 updated this revision to Diff 310378.Dec 8 2020, 3:58 PM
njames93 marked 2 inline comments as done.

Use pass by value for FileOptionsBaseProvider constructor.
Ping?

This revision is now accepted and ready to land.Dec 9 2020, 12:28 PM
This revision was landed with ongoing or failed builds.Dec 10 2020, 3:35 AM
This revision was automatically updated to reflect the committed changes.