Merge "init: fix clang-tidy performance issues"

This commit is contained in:
Tom Cherry 2019-07-12 18:49:49 +00:00 committed by Gerrit Code Review
commit 8a779ee959
10 changed files with 18 additions and 18 deletions

View file

@ -95,7 +95,7 @@ Result<void> Action::AddCommand(std::vector<std::string>&& args, int line) {
} }
void Action::AddCommand(BuiltinFunction f, std::vector<std::string>&& args, int line) { void Action::AddCommand(BuiltinFunction f, std::vector<std::string>&& args, int line) {
commands_.emplace_back(f, false, std::move(args), line); commands_.emplace_back(std::move(f), false, std::move(args), line);
} }
std::size_t Action::NumCommands() const { std::size_t Action::NumCommands() const {

View file

@ -47,7 +47,7 @@ void ActionManager::QueueAllPropertyActions() {
void ActionManager::QueueBuiltinAction(BuiltinFunction func, const std::string& name) { void ActionManager::QueueBuiltinAction(BuiltinFunction func, const std::string& name) {
auto action = std::make_unique<Action>(true, nullptr, "<Builtin Action>", 0, name, auto action = std::make_unique<Action>(true, nullptr, "<Builtin Action>", 0, name,
std::map<std::string, std::string>{}); std::map<std::string, std::string>{});
action->AddCommand(func, {name}, 0); action->AddCommand(std::move(func), {name}, 0);
event_queue_.emplace(action.get()); event_queue_.emplace(action.get());
actions_.emplace_back(std::move(action)); actions_.emplace_back(std::move(action));

View file

@ -84,9 +84,9 @@ class Subsystem {
}; };
Subsystem() {} Subsystem() {}
Subsystem(const std::string& name) : name_(name) {} Subsystem(std::string name) : name_(std::move(name)) {}
Subsystem(const std::string& name, DevnameSource source, const std::string& dir_name) Subsystem(std::string name, DevnameSource source, std::string dir_name)
: name_(name), devname_source_(source), dir_name_(dir_name) {} : name_(std::move(name)), devname_source_(source), dir_name_(std::move(dir_name)) {}
// Returns the full path for a uevent of a device that is a member of this subsystem, // Returns the full path for a uevent of a device that is a member of this subsystem,
// according to the rules parsed from ueventd.rc // according to the rules parsed from ueventd.rc

View file

@ -30,7 +30,7 @@ namespace init {
class DeviceHandlerTester { class DeviceHandlerTester {
public: public:
void TestGetSymlinks(const std::string& platform_device, const Uevent& uevent, void TestGetSymlinks(const std::string& platform_device, const Uevent& uevent,
const std::vector<std::string> expected_links) { const std::vector<std::string>& expected_links) {
TemporaryDir fake_sys_root; TemporaryDir fake_sys_root;
device_handler_.sysfs_mount_point_ = fake_sys_root.path; device_handler_.sysfs_mount_point_ = fake_sys_root.path;

View file

@ -285,7 +285,7 @@ void Keychords::Register(const std::vector<int>& keycodes) {
void Keychords::Start(Epoll* epoll, std::function<void(const std::vector<int>&)> handler) { void Keychords::Start(Epoll* epoll, std::function<void(const std::vector<int>&)> handler) {
epoll_ = epoll; epoll_ = epoll;
handler_ = handler; handler_ = std::move(handler);
if (entries_.size()) GeteventOpenDevice(); if (entries_.size()) GeteventOpenDevice();
} }

View file

@ -140,11 +140,11 @@ void MountHandler::MountHandlerFunction() {
} }
} }
free(buf); free(buf);
for (auto entry : untouched) { for (auto& entry : untouched) {
SetMountProperty(entry, false); SetMountProperty(entry, false);
mounts_.erase(entry); mounts_.erase(entry);
} }
for (auto entry : touched) { for (auto& entry : touched) {
SetMountProperty(entry, true); SetMountProperty(entry, true);
mounts_.emplace(std::move(entry)); mounts_.emplace(std::move(entry));
} }

View file

@ -37,7 +37,7 @@ void Parser::AddSectionParser(const std::string& name, std::unique_ptr<SectionPa
} }
void Parser::AddSingleLineParser(const std::string& prefix, LineCallback callback) { void Parser::AddSingleLineParser(const std::string& prefix, LineCallback callback) {
line_callbacks_.emplace_back(prefix, callback); line_callbacks_.emplace_back(prefix, std::move(callback));
} }
void Parser::ParseData(const std::string& filename, std::string* data) { void Parser::ParseData(const std::string& filename, std::string* data) {

View file

@ -83,7 +83,7 @@ Result<void> MixHwrngIntoLinuxRngAction(const BuiltinArguments&) {
return {}; return {};
} }
static bool SetHighestAvailableOptionValue(std::string path, int min, int max) { static bool SetHighestAvailableOptionValue(const std::string& path, int min, int max) {
std::ifstream inf(path, std::fstream::in); std::ifstream inf(path, std::fstream::in);
if (!inf) { if (!inf) {
LOG(ERROR) << "Cannot open for reading: " << path; LOG(ERROR) << "Cannot open for reading: " << path;

View file

@ -30,17 +30,17 @@ class TestFunctionMap : public KeywordFunctionMap {
public: public:
// Helper for argument-less functions // Helper for argument-less functions
using BuiltinFunctionNoArgs = std::function<void(void)>; using BuiltinFunctionNoArgs = std::function<void(void)>;
void Add(const std::string& name, const BuiltinFunctionNoArgs function) { void Add(const std::string& name, BuiltinFunctionNoArgs function) {
Add(name, 0, 0, false, [function](const BuiltinArguments&) { Add(name, 0, 0, false, [f = std::move(function)](const BuiltinArguments&) {
function(); f();
return Result<void>{}; return Result<void>{};
}); });
} }
void Add(const std::string& name, std::size_t min_parameters, std::size_t max_parameters, void Add(const std::string& name, std::size_t min_parameters, std::size_t max_parameters,
bool run_in_subcontext, const BuiltinFunction function) { bool run_in_subcontext, BuiltinFunction function) {
builtin_functions_[name] = builtin_functions_[name] = make_tuple(min_parameters, max_parameters,
make_tuple(min_parameters, max_parameters, make_pair(run_in_subcontext, function)); make_pair(run_in_subcontext, std::move(function)));
} }
private: private:

View file

@ -146,7 +146,7 @@ void ColdBoot::UeventHandlerMain(unsigned int process_num, unsigned int total_pr
void ColdBoot::RegenerateUevents() { void ColdBoot::RegenerateUevents() {
uevent_listener_.RegenerateUevents([this](const Uevent& uevent) { uevent_listener_.RegenerateUevents([this](const Uevent& uevent) {
uevent_queue_.emplace_back(std::move(uevent)); uevent_queue_.emplace_back(uevent);
return ListenerAction::kContinue; return ListenerAction::kContinue;
}); });
} }