Fix clang-tidy performance warnings in syste/core.

* Use const reference type for parameters to avoid unnecessary copy.
* Suppress warning of not using faster overloaded string find function.

Bug: 30407689
Bug: 30411878
Change-Id: I6cfdbbd50cf5e8f3db6e5263076d3a17a9a791ee
Test: build with WITH_TIDY=1
Merged-In: Ie79dbe21899867bc62031f8618bb1322b8071525
This commit is contained in:
Chih-Hung Hsieh 2016-07-27 16:25:51 -07:00
parent eafeb75c49
commit 8f7b9e3d39
10 changed files with 13 additions and 12 deletions

View file

@ -111,7 +111,7 @@ TEST(adb_utils, adb_dirname) {
EXPECT_EQ("/system/bin", adb_dirname("/system/bin/sh/"));
}
void test_mkdirs(const std::string basepath) {
void test_mkdirs(const std::string& basepath) {
// Test creating a directory hierarchy.
EXPECT_TRUE(mkdirs(basepath));
// Test finding an existing directory hierarchy.

View file

@ -1275,9 +1275,10 @@ static std::string find_product_out_path(const std::string& hint) {
return hint;
}
// If there are any slashes in it, assume it's a relative path;
// If any of the OS_PATH_SEPARATORS is found, assume it's a relative path;
// make it absolute.
if (hint.find_first_of(OS_PATH_SEPARATORS) != std::string::npos) {
// NOLINT: Do not complain if OS_PATH_SEPARATORS has only one character.
if (hint.find_first_of(OS_PATH_SEPARATORS) != std::string::npos) { // NOLINT
std::string cwd;
if (!getcwd(&cwd)) {
fprintf(stderr, "adb: getcwd failed: %s\n", strerror(errno));

View file

@ -433,7 +433,7 @@ class SyncConnection {
typedef void (sync_ls_cb)(unsigned mode, unsigned size, unsigned time, const char* name);
static bool sync_ls(SyncConnection& sc, const char* path,
std::function<sync_ls_cb> func) {
const std::function<sync_ls_cb>& func) {
if (!sc.SendRequest(ID_LIST, path)) return false;
while (true) {

View file

@ -835,7 +835,7 @@ static std::string verify_slot(Transport* transport, const char *slot) {
}
static void do_for_partition(Transport* transport, const char *part, const char *slot,
std::function<void(const std::string&)> func, bool force_slot) {
const std::function<void(const std::string&)>& func, bool force_slot) {
std::string has_slot;
std::string current_slot;
@ -867,7 +867,7 @@ static void do_for_partition(Transport* transport, const char *part, const char
* partition does not support slots.
*/
static void do_for_partitions(Transport* transport, const char *part, const char *slot,
std::function<void(const std::string&)> func, bool force_slot) {
const std::function<void(const std::string&)>& func, bool force_slot) {
std::string has_slot;
if (slot && strcmp(slot, "all") == 0) {

View file

@ -34,7 +34,7 @@ static constexpr int kTestTimeoutMs = 3000;
// Creates connected sockets |server| and |client|. Returns true on success.
bool MakeConnectedSockets(Socket::Protocol protocol, std::unique_ptr<Socket>* server,
std::unique_ptr<Socket>* client,
const std::string hostname = "localhost") {
const std::string& hostname = "localhost") {
*server = Socket::NewServer(protocol, 0);
if (*server == nullptr) {
ADD_FAILURE() << "Failed to create server.";

View file

@ -850,7 +850,7 @@ Service* ServiceManager::FindServiceByKeychord(int keychord_id) const {
return nullptr;
}
void ServiceManager::ForEachService(std::function<void(Service*)> callback) const {
void ServiceManager::ForEachService(const std::function<void(Service*)>& callback) const {
for (const auto& s : services_) {
callback(s.get());
}

View file

@ -177,7 +177,7 @@ public:
Service* FindServiceByName(const std::string& name) const;
Service* FindServiceByPid(pid_t pid) const;
Service* FindServiceByKeychord(int keychord_id) const;
void ForEachService(std::function<void(Service*)> callback) const;
void ForEachService(const std::function<void(Service*)>& callback) const;
void ForEachServiceInClass(const std::string& classname,
void (*func)(Service* svc)) const;
void ForEachServiceWithFlags(unsigned matchflags,

View file

@ -317,7 +317,7 @@ int wait_for_file(const char *filename, int timeout)
}
void import_kernel_cmdline(bool in_qemu,
std::function<void(const std::string&, const std::string&, bool)> fn) {
const std::function<void(const std::string&, const std::string&, bool)>& fn) {
std::string cmdline;
android::base::ReadFileToString("/proc/cmdline", &cmdline);

View file

@ -55,7 +55,7 @@ void make_link_init(const char *oldpath, const char *newpath);
void remove_link(const char *oldpath, const char *newpath);
int wait_for_file(const char *filename, int timeout);
void import_kernel_cmdline(bool in_qemu,
std::function<void(const std::string&, const std::string&, bool)>);
const std::function<void(const std::string&, const std::string&, bool)>&);
int make_dir(const char *path, mode_t mode);
int restorecon(const char *pathname);
int restorecon_recursive(const char *pathname);

View file

@ -73,7 +73,7 @@ static ucontext_t GetUContextFromUnwContext(const unw_context_t& unw_context) {
return ucontext;
}
static void OfflineBacktraceFunctionCall(std::function<int(void (*)(void*), void*)> function,
static void OfflineBacktraceFunctionCall(const std::function<int(void (*)(void*), void*)>& function,
std::vector<uintptr_t>* pc_values) {
// Create a thread to generate the needed stack and registers information.
g_exit_flag = false;