Fix clang-tidy performance warnings in frameworks/native.
* Use const reference parameter type to avoid unnecessary copy.
* Use more efficient overloaded string methods.
* Use const reference type for loop index variables to avoid unnecessary copy.
Bug: 30407689
Bug: 30411878
Bug: 30413223
Test: build with WITH_TIDY=1
Change-Id: I75ed62e2cb9939878b8932ed512ceb7e241edd6f
diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp
index 657323d..9e77e8f 100644
--- a/cmds/dumpstate/dumpstate.cpp
+++ b/cmds/dumpstate/dumpstate.cpp
@@ -691,7 +691,7 @@
std::string valid_name = entry_name;
// Rename extension if necessary.
- size_t idx = entry_name.rfind(".");
+ size_t idx = entry_name.rfind('.');
if (idx != std::string::npos) {
std::string extension = entry_name.substr(idx);
std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
@@ -1432,7 +1432,7 @@
return true;
}
-static std::string SHA256_file_hash(std::string filepath) {
+static std::string SHA256_file_hash(const std::string& filepath) {
android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(filepath.c_str(), O_RDONLY | O_NONBLOCK
| O_CLOEXEC | O_NOFOLLOW)));
if (fd == -1) {