Fix clang-tidy performance warnings in system/vold.
* Use const reference type for for-loop index variables
to avoid unnecessary copy.
Bug: 30413223
Change-Id: Id4d980ae8afec1374fc3be0b23f1c6a39bff86e0
Test: build with WITH_TIDY=1
diff --git a/VolumeManager.cpp b/VolumeManager.cpp
old mode 100755
new mode 100644
index 57b8753..001583f
--- a/VolumeManager.cpp
+++ b/VolumeManager.cpp
@@ -294,7 +294,7 @@
switch (evt->getAction()) {
case NetlinkEvent::Action::kAdd: {
- for (auto source : mDiskSources) {
+ for (const auto& source : mDiskSources) {
if (source->matches(eventPath)) {
// For now, assume that MMC devices are SD, and that
// everything else is USB
@@ -316,7 +316,7 @@
}
case NetlinkEvent::Action::kChange: {
LOG(DEBUG) << "Disk at " << major << ":" << minor << " changed";
- for (auto disk : mDisks) {
+ for (const auto& disk : mDisks) {
if (disk->getDevice() == device) {
disk->readMetadata();
disk->readPartitions();
@@ -360,7 +360,7 @@
if (mInternalEmulated->getId() == id) {
return mInternalEmulated;
}
- for (auto disk : mDisks) {
+ for (const auto& disk : mDisks) {
auto vol = disk->findVolume(id);
if (vol != nullptr) {
return vol;
@@ -372,7 +372,7 @@
void VolumeManager::listVolumes(android::vold::VolumeBase::Type type,
std::list<std::string>& list) {
list.clear();
- for (auto disk : mDisks) {
+ for (const auto& disk : mDisks) {
disk->listVolumes(type, list);
}
}
@@ -503,7 +503,7 @@
}
endmntent(fp);
- for (auto path : toUnmount) {
+ for (const auto& path : toUnmount) {
if (umount2(path.c_str(), MNT_DETACH)) {
ALOGW("Failed to unmount %s: %s", path.c_str(), strerror(errno));
}
@@ -629,7 +629,7 @@
// newly connected framework hears all events.
mInternalEmulated->destroy();
mInternalEmulated->create();
- for (auto disk : mDisks) {
+ for (const auto& disk : mDisks) {
disk->destroy();
disk->create();
}
@@ -640,7 +640,7 @@
int VolumeManager::shutdown() {
mInternalEmulated->destroy();
- for (auto disk : mDisks) {
+ for (const auto& disk : mDisks) {
disk->destroy();
}
mDisks.clear();
@@ -654,7 +654,7 @@
if (mInternalEmulated != nullptr) {
mInternalEmulated->unmount();
}
- for (auto disk : mDisks) {
+ for (const auto& disk : mDisks) {
disk->unmountAll();
}
@@ -678,7 +678,7 @@
}
endmntent(fp);
- for (auto path : toUnmount) {
+ for (const auto& path : toUnmount) {
SLOGW("Tearing down stale mount %s", path.c_str());
android::vold::ForceUnmount(path);
}