summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Chih-Hung Hsieh <chh@google.com> 2017-08-03 15:48:25 -0700
committer Chih-Hung Hsieh <chh@google.com> 2017-08-03 17:38:27 -0700
commitcb057c2e6bf23b43df49282c0db26b663e4535f7 (patch)
tree13c5977423159cd4e0be6bc3b2936c398b6004c7
parent10288989e36fee33e50e2a79bc6111b47cd729bb (diff)
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
-rw-r--r--cmds/atrace/atrace.cpp6
-rw-r--r--cmds/dumpstate/dumpstate.cpp4
-rw-r--r--cmds/dumpsys/dumpsys.cpp2
-rw-r--r--cmds/dumpsys/tests/dumpsys_test.cpp2
-rw-r--r--cmds/installd/CacheTracker.cpp4
-rw-r--r--cmds/installd/InstalldNativeService.cpp8
-rw-r--r--cmds/surfacereplayer/replayer/Replayer.cpp2
-rw-r--r--libs/gui/BufferQueueProducer.cpp2
-rw-r--r--opengl/tests/hwc/hwcRects.cpp4
9 files changed, 17 insertions, 17 deletions
diff --git a/cmds/atrace/atrace.cpp b/cmds/atrace/atrace.cpp
index 9cdc9e906d..a48dab97cb 100644
--- a/cmds/atrace/atrace.cpp
+++ b/cmds/atrace/atrace.cpp
@@ -481,8 +481,8 @@ static bool setClock()
newClock = "global";
}
- size_t begin = clockStr.find("[") + 1;
- size_t end = clockStr.find("]");
+ size_t begin = clockStr.find('[') + 1;
+ size_t end = clockStr.find(']');
if (newClock.compare(0, std::string::npos, clockStr, begin, end-begin) == 0) {
return true;
}
@@ -543,7 +543,7 @@ static void pokeHalServices()
auto listRet = sm->list([&](const auto &interfaces) {
for (size_t i = 0; i < interfaces.size(); i++) {
string fqInstanceName = interfaces[i];
- string::size_type n = fqInstanceName.find("/");
+ string::size_type n = fqInstanceName.find('/');
if (n == std::string::npos || interfaces[i].size() == n+1)
continue;
hidl_string fqInterfaceName = fqInstanceName.substr(0, n);
diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp
index 657323d90d..9e77e8fbcb 100644
--- a/cmds/dumpstate/dumpstate.cpp
+++ b/cmds/dumpstate/dumpstate.cpp
@@ -691,7 +691,7 @@ bool Dumpstate::AddZipEntryFromFd(const std::string& entry_name, int fd) {
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 @@ bool Dumpstate::FinishZipFile() {
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) {
diff --git a/cmds/dumpsys/dumpsys.cpp b/cmds/dumpsys/dumpsys.cpp
index f0e7200069..73c7f18236 100644
--- a/cmds/dumpsys/dumpsys.cpp
+++ b/cmds/dumpsys/dumpsys.cpp
@@ -176,7 +176,7 @@ int Dumpsys::main(int argc, char* const argv[]) {
}
for (size_t i = 0; i < N; i++) {
- String16 service_name = std::move(services[i]);
+ const String16& service_name = std::move(services[i]);
if (IsSkipped(skippedServices, service_name)) continue;
sp<IBinder> service = sm_->checkService(service_name);
diff --git a/cmds/dumpsys/tests/dumpsys_test.cpp b/cmds/dumpsys/tests/dumpsys_test.cpp
index 66beb6d4e0..5ca2b578a6 100644
--- a/cmds/dumpsys/tests/dumpsys_test.cpp
+++ b/cmds/dumpsys/tests/dumpsys_test.cpp
@@ -95,7 +95,7 @@ MATCHER_P(AndroidElementsAre, expected, "") {
}
int i = 0;
std::ostringstream actual_stream, expected_stream;
- for (String16 actual : arg) {
+ for (const String16& actual : arg) {
std::string actual_str = String8(actual).c_str();
std::string expected_str = expected[i];
actual_stream << "'" << actual_str << "' ";
diff --git a/cmds/installd/CacheTracker.cpp b/cmds/installd/CacheTracker.cpp
index 3eb39b9bed..ea0cd9e4e2 100644
--- a/cmds/installd/CacheTracker.cpp
+++ b/cmds/installd/CacheTracker.cpp
@@ -60,7 +60,7 @@ void CacheTracker::loadStats() {
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 @@ void CacheTracker::loadItems() {
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 a711813b05..79c77dcd7b 100644
--- a/cmds/installd/InstalldNativeService.cpp
+++ b/cmds/installd/InstalldNativeService.cpp
@@ -1344,7 +1344,7 @@ binder::Status InstalldNativeService::getAppSize(const std::unique_ptr<std::stri
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
@@ -1383,7 +1383,7 @@ binder::Status InstalldNativeService::getAppSize(const std::unique_ptr<std::stri
}
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);
}
@@ -1391,7 +1391,7 @@ binder::Status InstalldNativeService::getAppSize(const std::unique_ptr<std::stri
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));
}
@@ -1402,7 +1402,7 @@ binder::Status InstalldNativeService::getAppSize(const std::unique_ptr<std::stri
ATRACE_END();
} else {
ATRACE_BEGIN("code");
- for (auto codePath : codePaths) {
+ for (const auto& codePath : codePaths) {
calculate_tree_size(codePath, &stats.codeSize);
}
ATRACE_END();
diff --git a/cmds/surfacereplayer/replayer/Replayer.cpp b/cmds/surfacereplayer/replayer/Replayer.cpp
index 35b63ec5c3..2b5389b8dc 100644
--- a/cmds/surfacereplayer/replayer/Replayer.cpp
+++ b/cmds/surfacereplayer/replayer/Replayer.cpp
@@ -505,7 +505,7 @@ status_t Replayer::setTransparentRegionHint(layer_id id, const TransparentRegion
ALOGV("Setting Transparent Region Hint");
Region re = Region();
- for (auto r : trhc.region()) {
+ for (const auto& r : trhc.region()) {
Rect rect = Rect(r.left(), r.top(), r.right(), r.bottom());
re.merge(rect);
}
diff --git a/libs/gui/BufferQueueProducer.cpp b/libs/gui/BufferQueueProducer.cpp
index 3424012acf..bcfa7bccd7 100644
--- a/libs/gui/BufferQueueProducer.cpp
+++ b/libs/gui/BufferQueueProducer.cpp
@@ -764,7 +764,7 @@ status_t BufferQueueProducer::queueBuffer(int slot,
input.deflate(&requestedPresentTimestamp, &isAutoTimestamp, &dataSpace,
&crop, &scalingMode, &transform, &acquireFence, &stickyTransform,
&getFrameTimestamps);
- Region surfaceDamage = input.getSurfaceDamage();
+ const Region& surfaceDamage = input.getSurfaceDamage();
if (acquireFence == NULL) {
BQ_LOGE("queueBuffer: fence is NULL");
diff --git a/opengl/tests/hwc/hwcRects.cpp b/opengl/tests/hwc/hwcRects.cpp
index 69e56ff59b..5956366809 100644
--- a/opengl/tests/hwc/hwcRects.cpp
+++ b/opengl/tests/hwc/hwcRects.cpp
@@ -170,7 +170,7 @@ static EGLSurface surface;
static EGLint width, height;
// Function prototypes
-static Rectangle parseRect(string rectStr);
+static Rectangle parseRect(const string& rectStr);
void init(void);
void printSyntax(const char *cmd);
@@ -358,7 +358,7 @@ main(int argc, char *argv[])
// Parse string description of rectangle and add it to list of rectangles
// to be rendered.
-static Rectangle parseRect(string rectStr)
+static Rectangle parseRect(const string& rectStr)
{
int rv;
string str;