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.
(cherry picked from commit cb057c2e6bf23b43df49282c0db26b663e4535f7)
Bug: 30407689
Bug: 30411878
Bug: 30413223
Test: build with WITH_TIDY=1
Merged-In: I75ed62e2cb9939878b8932ed512ceb7e241edd6f
Change-Id: I75ed62e2cb9939878b8932ed512ceb7e241edd6f
diff --git a/cmds/installd/CacheTracker.cpp b/cmds/installd/CacheTracker.cpp
index 3eb39b9..ea0cd9e 100644
--- a/cmds/installd/CacheTracker.cpp
+++ b/cmds/installd/CacheTracker.cpp
@@ -60,7 +60,7 @@
ATRACE_BEGIN("loadStats tree");
cacheUsed = 0;
- for (auto path : mDataPaths) {
+ for (const auto& path : mDataPaths) {
auto cachePath = read_path_inode(path, "cache", kXattrInodeCache);
auto codeCachePath = read_path_inode(path, "code_cache", kXattrInodeCodeCache);
calculate_tree_size(cachePath, &cacheUsed);
@@ -170,7 +170,7 @@
items.clear();
ATRACE_BEGIN("loadItems");
- for (auto path : mDataPaths) {
+ for (const auto& path : mDataPaths) {
loadItemsFrom(read_path_inode(path, "cache", kXattrInodeCache));
loadItemsFrom(read_path_inode(path, "code_cache", kXattrInodeCodeCache));
}
diff --git a/cmds/installd/InstalldNativeService.cpp b/cmds/installd/InstalldNativeService.cpp
index 054c88e..c087713 100644
--- a/cmds/installd/InstalldNativeService.cpp
+++ b/cmds/installd/InstalldNativeService.cpp
@@ -1347,7 +1347,7 @@
const std::vector<std::string>& codePaths, std::vector<int64_t>* _aidl_return) {
ENFORCE_UID(AID_SYSTEM);
CHECK_ARGUMENT_UUID(uuid);
- for (auto packageName : packageNames) {
+ for (const auto& packageName : packageNames) {
CHECK_ARGUMENT_PACKAGE_NAME(packageName);
}
// NOTE: Locking is relaxed on this method, since it's limited to
@@ -1386,7 +1386,7 @@
}
ATRACE_BEGIN("obb");
- for (auto packageName : packageNames) {
+ for (const auto& packageName : packageNames) {
auto obbCodePath = create_data_media_obb_path(uuid_, packageName.c_str());
calculate_tree_size(obbCodePath, &extStats.codeSize);
}
@@ -1394,7 +1394,7 @@
if (flags & FLAG_USE_QUOTA && appId >= AID_APP_START) {
ATRACE_BEGIN("code");
- for (auto codePath : codePaths) {
+ for (const auto& codePath : codePaths) {
calculate_tree_size(codePath, &stats.codeSize, -1,
multiuser_get_shared_gid(0, appId));
}
@@ -1405,7 +1405,7 @@
ATRACE_END();
} else {
ATRACE_BEGIN("code");
- for (auto codePath : codePaths) {
+ for (const auto& codePath : codePaths) {
calculate_tree_size(codePath, &stats.codeSize);
}
ATRACE_END();