summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChih-Hung Hsieh <chh@google.com>2018-12-11 11:09:20 -0800
committerChih-hung Hsieh <chh@google.com>2018-12-17 20:00:55 +0000
commita1b644e88cfe5319e9ada7ad24e6cd215a7ea402 (patch)
treee4b24972d2c59b6512cd981b3edf78b03f7c1add
parentd0c404cb21de6e86329b5ceb79d1459dd8f2f4cb (diff)
Fix performance-for-range-copy warnings
Bug: 30413223 Test: make with WITH_TIDY=1 DEFAULT_GLOBAL_TIDY_CHECKS=-*,performance* Change-Id: Ie481e88025a7a1f3abde8ff63420d5ccd8577e52
-rw-r--r--cmds/statsd/src/config/ConfigManager.cpp16
-rw-r--r--cmds/statsd/src/external/SubsystemSleepStatePuller.cpp2
-rw-r--r--cmds/statsd/src/metrics/MetricsManager.cpp2
-rw-r--r--cmds/statsd/src/metrics/metrics_manager_util.cpp2
-rw-r--r--cmds/statsd/src/packages/UidMap.cpp6
-rw-r--r--cmds/statsd/tests/anomaly/AnomalyTracker_test.cpp4
-rw-r--r--core/jni/com_android_internal_os_Zygote.cpp2
-rw-r--r--libs/hwui/tests/common/scenes/ShapeAnimation.cpp2
-rw-r--r--libs/hwui/tests/unit/VectorDrawableTests.cpp16
-rw-r--r--tools/aapt2/ResourceParser.cpp2
-rw-r--r--tools/aapt2/ResourceUtils.cpp2
-rw-r--r--tools/aapt2/cmd/Compile.cpp2
-rw-r--r--tools/aapt2/java/AnnotationProcessor.cpp2
-rw-r--r--tools/aapt2/util/Files.cpp2
14 files changed, 31 insertions, 31 deletions
diff --git a/cmds/statsd/src/config/ConfigManager.cpp b/cmds/statsd/src/config/ConfigManager.cpp
index 16b7e79c0ed7..5fea90b61c80 100644
--- a/cmds/statsd/src/config/ConfigManager.cpp
+++ b/cmds/statsd/src/config/ConfigManager.cpp
@@ -106,14 +106,14 @@ void ConfigManager::UpdateConfig(const ConfigKey& key, const StatsdConfig& confi
// Add to set.
mConfigs[key.GetUid()].insert(key);
- for (sp<ConfigListener> listener : mListeners) {
+ for (const sp<ConfigListener>& listener : mListeners) {
broadcastList.push_back(listener);
}
}
const int64_t timestampNs = getElapsedRealtimeNs();
// Tell everyone
- for (sp<ConfigListener> listener : broadcastList) {
+ for (const sp<ConfigListener>& listener : broadcastList) {
listener->OnConfigUpdated(timestampNs, key, config);
}
}
@@ -137,7 +137,7 @@ void ConfigManager::RemoveConfig(const ConfigKey& key) {
if (uidIt != mConfigs.end() && uidIt->second.find(key) != uidIt->second.end()) {
// Remove from map
uidIt->second.erase(key);
- for (sp<ConfigListener> listener : mListeners) {
+ for (const sp<ConfigListener>& listener : mListeners) {
broadcastList.push_back(listener);
}
}
@@ -153,7 +153,7 @@ void ConfigManager::RemoveConfig(const ConfigKey& key) {
remove_saved_configs(key);
}
- for (sp<ConfigListener> listener:broadcastList) {
+ for (const sp<ConfigListener>& listener:broadcastList) {
listener->OnConfigRemoved(key);
}
}
@@ -183,7 +183,7 @@ void ConfigManager::RemoveConfigs(int uid) {
mConfigs.erase(uidIt);
- for (sp<ConfigListener> listener : mListeners) {
+ for (const sp<ConfigListener>& listener : mListeners) {
broadcastList.push_back(listener);
}
}
@@ -191,7 +191,7 @@ void ConfigManager::RemoveConfigs(int uid) {
// Remove separately so if they do anything in the callback they can't mess up our iteration.
for (auto& key : removed) {
// Tell everyone
- for (sp<ConfigListener> listener:broadcastList) {
+ for (const sp<ConfigListener>& listener:broadcastList) {
listener->OnConfigRemoved(key);
}
}
@@ -213,7 +213,7 @@ void ConfigManager::RemoveAllConfigs() {
}
mConfigReceivers.clear();
- for (sp<ConfigListener> listener : mListeners) {
+ for (const sp<ConfigListener>& listener : mListeners) {
broadcastList.push_back(listener);
}
}
@@ -221,7 +221,7 @@ void ConfigManager::RemoveAllConfigs() {
// Remove separately so if they do anything in the callback they can't mess up our iteration.
for (auto& key : removed) {
// Tell everyone
- for (sp<ConfigListener> listener:broadcastList) {
+ for (const sp<ConfigListener>& listener:broadcastList) {
listener->OnConfigRemoved(key);
}
}
diff --git a/cmds/statsd/src/external/SubsystemSleepStatePuller.cpp b/cmds/statsd/src/external/SubsystemSleepStatePuller.cpp
index 4501b64ad47e..2713d327995d 100644
--- a/cmds/statsd/src/external/SubsystemSleepStatePuller.cpp
+++ b/cmds/statsd/src/external/SubsystemSleepStatePuller.cpp
@@ -111,7 +111,7 @@ bool SubsystemSleepStatePuller::PullInternal(vector<shared_ptr<LogEvent>>* data)
(long long)state.residencyInMsecSinceBoot,
(long long)state.totalTransitions,
state.supportedOnlyInSuspend ? 1 : 0);
- for (auto voter : state.voters) {
+ for (const auto& voter : state.voters) {
auto voterPtr = make_shared<LogEvent>(
android::util::SUBSYSTEM_SLEEP_STATE,
wallClockTimestampNs, elapsedTimestampNs);
diff --git a/cmds/statsd/src/metrics/MetricsManager.cpp b/cmds/statsd/src/metrics/MetricsManager.cpp
index 4fac0e1a141b..a6c7f3a0dc87 100644
--- a/cmds/statsd/src/metrics/MetricsManager.cpp
+++ b/cmds/statsd/src/metrics/MetricsManager.cpp
@@ -395,7 +395,7 @@ void MetricsManager::onPeriodicAlarmFired(
// Returns the total byte size of all metrics managed by a single config source.
size_t MetricsManager::byteSize() {
size_t totalSize = 0;
- for (auto metricProducer : mAllMetricProducers) {
+ for (const auto& metricProducer : mAllMetricProducers) {
totalSize += metricProducer->byteSize();
}
return totalSize;
diff --git a/cmds/statsd/src/metrics/metrics_manager_util.cpp b/cmds/statsd/src/metrics/metrics_manager_util.cpp
index 811a00e47ae5..a1c80b84f9b1 100644
--- a/cmds/statsd/src/metrics/metrics_manager_util.cpp
+++ b/cmds/statsd/src/metrics/metrics_manager_util.cpp
@@ -537,7 +537,7 @@ bool initMetrics(const ConfigKey& key, const StatsdConfig& config,
}
noReportMetricIds.insert(no_report_metric);
}
- for (auto it : allMetricProducers) {
+ for (const auto& it : allMetricProducers) {
uidMap.addListener(it);
}
return true;
diff --git a/cmds/statsd/src/packages/UidMap.cpp b/cmds/statsd/src/packages/UidMap.cpp
index 73ac9686889e..88957df87d08 100644
--- a/cmds/statsd/src/packages/UidMap.cpp
+++ b/cmds/statsd/src/packages/UidMap.cpp
@@ -141,7 +141,7 @@ void UidMap::updateMap(const int64_t& timestamp, const vector<int32_t>& uid,
// listener removes itself before we call it. It's then the listener's job to handle it (expect
// the callback to be called after listener is removed, and the listener should properly
// ignore it).
- for (auto weakPtr : broadcastList) {
+ for (const auto& weakPtr : broadcastList) {
auto strongPtr = weakPtr.promote();
if (strongPtr != NULL) {
strongPtr->onUidMapReceived(timestamp);
@@ -181,7 +181,7 @@ void UidMap::updateApp(const int64_t& timestamp, const String16& app_16, const i
StatsdStats::getInstance().setUidMapChanges(mChanges.size());
}
- for (auto weakPtr : broadcastList) {
+ for (const auto& weakPtr : broadcastList) {
auto strongPtr = weakPtr.promote();
if (strongPtr != NULL) {
strongPtr->notifyAppUpgrade(timestamp, appName, uid, versionCode);
@@ -248,7 +248,7 @@ void UidMap::removeApp(const int64_t& timestamp, const String16& app_16, const i
getListenerListCopyLocked(&broadcastList);
}
- for (auto weakPtr : broadcastList) {
+ for (const auto& weakPtr : broadcastList) {
auto strongPtr = weakPtr.promote();
if (strongPtr != NULL) {
strongPtr->notifyAppRemoved(timestamp, app, uid);
diff --git a/cmds/statsd/tests/anomaly/AnomalyTracker_test.cpp b/cmds/statsd/tests/anomaly/AnomalyTracker_test.cpp
index 218d52a5c046..e1258875551e 100644
--- a/cmds/statsd/tests/anomaly/AnomalyTracker_test.cpp
+++ b/cmds/statsd/tests/anomaly/AnomalyTracker_test.cpp
@@ -71,12 +71,12 @@ bool detectAnomaliesPass(AnomalyTracker& tracker,
const std::shared_ptr<DimToValMap>& currentBucket,
const std::set<const MetricDimensionKey>& trueList,
const std::set<const MetricDimensionKey>& falseList) {
- for (MetricDimensionKey key : trueList) {
+ for (const MetricDimensionKey& key : trueList) {
if (!tracker.detectAnomaly(bucketNum, key, getBucketValue(currentBucket, key))) {
return false;
}
}
- for (MetricDimensionKey key : falseList) {
+ for (const MetricDimensionKey& key : falseList) {
if (tracker.detectAnomaly(bucketNum, key, getBucketValue(currentBucket, key))) {
return false;
}
diff --git a/core/jni/com_android_internal_os_Zygote.cpp b/core/jni/com_android_internal_os_Zygote.cpp
index 01105ba04be3..2e6b1b95fc3d 100644
--- a/core/jni/com_android_internal_os_Zygote.cpp
+++ b/core/jni/com_android_internal_os_Zygote.cpp
@@ -414,7 +414,7 @@ static int UnmountTree(const char* path) {
}
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));
}
diff --git a/libs/hwui/tests/common/scenes/ShapeAnimation.cpp b/libs/hwui/tests/common/scenes/ShapeAnimation.cpp
index 0d87776e083e..d189a9379c33 100644
--- a/libs/hwui/tests/common/scenes/ShapeAnimation.cpp
+++ b/libs/hwui/tests/common/scenes/ShapeAnimation.cpp
@@ -76,7 +76,7 @@ public:
paint.setStrokeWidth(strokeWidth);
// fill column with each op
int middleCount = canvas.save(SaveFlags::MatrixClip);
- for (auto op : ops) {
+ for (const auto& op : ops) {
int innerCount = canvas.save(SaveFlags::MatrixClip);
canvas.clipRect(0, 0, cellSize, cellSize, SkClipOp::kIntersect);
canvas.drawColor(Color::White, SkBlendMode::kSrcOver);
diff --git a/libs/hwui/tests/unit/VectorDrawableTests.cpp b/libs/hwui/tests/unit/VectorDrawableTests.cpp
index 02f740cee096..4f299e377f09 100644
--- a/libs/hwui/tests/unit/VectorDrawableTests.cpp
+++ b/libs/hwui/tests/unit/VectorDrawableTests.cpp
@@ -251,7 +251,7 @@ static bool hasSameVerbs(const PathData& from, const PathData& to) {
}
TEST(PathParser, parseStringForData) {
- for (TestData testData : sTestDataSet) {
+ for (const TestData& testData : sTestDataSet) {
PathParser::ParseResult result;
// Test generated path data against the given data.
PathData pathData;
@@ -271,7 +271,7 @@ TEST(PathParser, parseStringForData) {
}
TEST(VectorDrawableUtils, createSkPathFromPathData) {
- for (TestData testData : sTestDataSet) {
+ for (const TestData& testData : sTestDataSet) {
SkPath expectedPath;
testData.skPathLamda(&expectedPath);
SkPath actualPath;
@@ -281,7 +281,7 @@ TEST(VectorDrawableUtils, createSkPathFromPathData) {
}
TEST(PathParser, parseAsciiStringForSkPath) {
- for (TestData testData : sTestDataSet) {
+ for (const TestData& testData : sTestDataSet) {
PathParser::ParseResult result;
size_t length = strlen(testData.pathString);
// Check the return value as well as the SkPath generated.
@@ -304,8 +304,8 @@ TEST(PathParser, parseAsciiStringForSkPath) {
}
TEST(VectorDrawableUtils, morphPathData) {
- for (TestData fromData : sTestDataSet) {
- for (TestData toData : sTestDataSet) {
+ for (const TestData& fromData : sTestDataSet) {
+ for (const TestData& toData : sTestDataSet) {
bool canMorph = VectorDrawableUtils::canMorph(fromData.pathData, toData.pathData);
if (fromData.pathData == toData.pathData) {
EXPECT_TRUE(canMorph);
@@ -319,8 +319,8 @@ TEST(VectorDrawableUtils, morphPathData) {
TEST(VectorDrawableUtils, interpolatePathData) {
// Interpolate path data with itself and every other path data
- for (TestData fromData : sTestDataSet) {
- for (TestData toData : sTestDataSet) {
+ for (const TestData& fromData : sTestDataSet) {
+ for (const TestData& toData : sTestDataSet) {
PathData outData;
bool success = VectorDrawableUtils::interpolatePathData(&outData, fromData.pathData,
toData.pathData, 0.5);
@@ -331,7 +331,7 @@ TEST(VectorDrawableUtils, interpolatePathData) {
float fractions[] = {0, 0.00001, 0.28, 0.5, 0.7777, 0.9999999, 1};
// Now try to interpolate with a slightly modified version of self and expect success
- for (TestData fromData : sTestDataSet) {
+ for (const TestData& fromData : sTestDataSet) {
PathData toPathData = fromData.pathData;
for (size_t i = 0; i < toPathData.points.size(); i++) {
toPathData.points[i]++;
diff --git a/tools/aapt2/ResourceParser.cpp b/tools/aapt2/ResourceParser.cpp
index 39ca80bbcf51..968376b8229b 100644
--- a/tools/aapt2/ResourceParser.cpp
+++ b/tools/aapt2/ResourceParser.cpp
@@ -78,7 +78,7 @@ static uint32_t ParseFormatType(const StringPiece& piece) {
static uint32_t ParseFormatAttribute(const StringPiece& str) {
uint32_t mask = 0;
- for (StringPiece part : util::Tokenize(str, '|')) {
+ for (const StringPiece& part : util::Tokenize(str, '|')) {
StringPiece trimmed_part = util::TrimWhitespace(part);
uint32_t type = ParseFormatType(trimmed_part);
if (type == 0) {
diff --git a/tools/aapt2/ResourceUtils.cpp b/tools/aapt2/ResourceUtils.cpp
index 82d9e041b41a..99420de47fca 100644
--- a/tools/aapt2/ResourceUtils.cpp
+++ b/tools/aapt2/ResourceUtils.cpp
@@ -360,7 +360,7 @@ std::unique_ptr<BinaryPrimitive> TryParseFlagSymbol(const Attribute* flag_attr,
return util::make_unique<BinaryPrimitive>(flags);
}
- for (StringPiece part : util::Tokenize(str, '|')) {
+ for (const StringPiece& part : util::Tokenize(str, '|')) {
StringPiece trimmed_part = util::TrimWhitespace(part);
bool flag_set = false;
diff --git a/tools/aapt2/cmd/Compile.cpp b/tools/aapt2/cmd/Compile.cpp
index 411ad747faa3..0b43c5d4a808 100644
--- a/tools/aapt2/cmd/Compile.cpp
+++ b/tools/aapt2/cmd/Compile.cpp
@@ -486,7 +486,7 @@ static bool CompileXml(IAaptContext* context, const CompileOptions& options,
}
Printer r_txt_printer(&fout_text);
- for (const auto res : xmlres->file.exported_symbols) {
+ for (const auto& res : xmlres->file.exported_symbols) {
r_txt_printer.Print("default int id ");
r_txt_printer.Println(res.name.entry);
}
diff --git a/tools/aapt2/java/AnnotationProcessor.cpp b/tools/aapt2/java/AnnotationProcessor.cpp
index 8d91b0098c1f..a4610b2575b9 100644
--- a/tools/aapt2/java/AnnotationProcessor.cpp
+++ b/tools/aapt2/java/AnnotationProcessor.cpp
@@ -113,7 +113,7 @@ void AnnotationProcessor::AppendNewLine() {
void AnnotationProcessor::Print(Printer* printer) const {
if (has_comments_) {
std::string result = comment_.str();
- for (StringPiece line : util::Tokenize(result, '\n')) {
+ for (const StringPiece& line : util::Tokenize(result, '\n')) {
printer->Println(line);
}
printer->Println(" */");
diff --git a/tools/aapt2/util/Files.cpp b/tools/aapt2/util/Files.cpp
index 5a8ff0926483..a407c228503a 100644
--- a/tools/aapt2/util/Files.cpp
+++ b/tools/aapt2/util/Files.cpp
@@ -165,7 +165,7 @@ void AppendPath(std::string* base, StringPiece part) {
std::string PackageToPath(const StringPiece& package) {
std::string out_path;
- for (StringPiece part : util::Tokenize(package, '.')) {
+ for (const StringPiece& part : util::Tokenize(package, '.')) {
AppendPath(&out_path, part);
}
return out_path;