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: Ie79dbe21899867bc62031f8618bb1322b8071525
Test: build with WITH_TIDY=1
This commit is contained in:
Chih-Hung Hsieh 2016-07-28 16:38:15 -07:00
parent 1b218d6cb9
commit a32ce535f9
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

@ -1310,9 +1310,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

@ -969,7 +969,7 @@ static std::string verify_slot(Transport* transport, const std::string& slot) {
}
static void do_for_partition(Transport* transport, const std::string& part, const std::string& 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;
@ -1002,7 +1002,7 @@ static void do_for_partition(Transport* transport, const std::string& part, cons
* partition does not support slots.
*/
static void do_for_partitions(Transport* transport, const std::string& part, const std::string& 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 == "all") {

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;