diff --git a/cmds/statsd/src/config/ConfigManager.cpp b/cmds/statsd/src/config/ConfigManager.cpp index 16b7e79c0ed7e..5fea90b61c80b 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 listener : mListeners) { + for (const sp& listener : mListeners) { broadcastList.push_back(listener); } } const int64_t timestampNs = getElapsedRealtimeNs(); // Tell everyone - for (sp listener : broadcastList) { + for (const sp& 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 listener : mListeners) { + for (const sp& listener : mListeners) { broadcastList.push_back(listener); } } @@ -153,7 +153,7 @@ void ConfigManager::RemoveConfig(const ConfigKey& key) { remove_saved_configs(key); } - for (sp listener:broadcastList) { + for (const sp& listener:broadcastList) { listener->OnConfigRemoved(key); } } @@ -183,7 +183,7 @@ void ConfigManager::RemoveConfigs(int uid) { mConfigs.erase(uidIt); - for (sp listener : mListeners) { + for (const sp& 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 listener:broadcastList) { + for (const sp& listener:broadcastList) { listener->OnConfigRemoved(key); } } @@ -213,7 +213,7 @@ void ConfigManager::RemoveAllConfigs() { } mConfigReceivers.clear(); - for (sp listener : mListeners) { + for (const sp& 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 listener:broadcastList) { + for (const sp& listener:broadcastList) { listener->OnConfigRemoved(key); } } diff --git a/cmds/statsd/src/external/SubsystemSleepStatePuller.cpp b/cmds/statsd/src/external/SubsystemSleepStatePuller.cpp index c8c392016e52b..d8229599635c1 100644 --- a/cmds/statsd/src/external/SubsystemSleepStatePuller.cpp +++ b/cmds/statsd/src/external/SubsystemSleepStatePuller.cpp @@ -281,7 +281,7 @@ bool getIPowerDataLocked(vector>* 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( android::util::SUBSYSTEM_SLEEP_STATE, wallClockTimestampNs, elapsedTimestampNs); diff --git a/cmds/statsd/src/metrics/MetricsManager.cpp b/cmds/statsd/src/metrics/MetricsManager.cpp index ac34f4760a12b..dd969c0e9c20e 100644 --- a/cmds/statsd/src/metrics/MetricsManager.cpp +++ b/cmds/statsd/src/metrics/MetricsManager.cpp @@ -412,7 +412,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 b317361a5a3d2..180a1ae07523d 100644 --- a/cmds/statsd/src/metrics/metrics_manager_util.cpp +++ b/cmds/statsd/src/metrics/metrics_manager_util.cpp @@ -598,7 +598,7 @@ bool initMetrics(const ConfigKey& key, const StatsdConfig& config, const int64_t } 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 59f3f0448e0e8..e9c43cdbf31f5 100644 --- a/cmds/statsd/src/packages/UidMap.cpp +++ b/cmds/statsd/src/packages/UidMap.cpp @@ -152,7 +152,7 @@ void UidMap::updateMap(const int64_t& timestamp, const vector& 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); @@ -200,7 +200,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); @@ -269,7 +269,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 79bed52f02028..960fbdab1c159 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& currentBucket, const std::set& trueList, const std::set& 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 7032081ef6a02..ff4591fb7f453 100644 --- a/core/jni/com_android_internal_os_Zygote.cpp +++ b/core/jni/com_android_internal_os_Zygote.cpp @@ -418,7 +418,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 0d87776e083ef..d189a9379c33b 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 ee6beba847a03..b11eaa9d6a2f7 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 95877045072bd..c91134c167ed1 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 da22e885b9171..c6f91527c91cd 100644 --- a/tools/aapt2/ResourceUtils.cpp +++ b/tools/aapt2/ResourceUtils.cpp @@ -362,7 +362,7 @@ std::unique_ptr TryParseFlagSymbol(const Attribute* flag_attr, return util::make_unique(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 fc9514a691d28..f63a0745690b4 100644 --- a/tools/aapt2/cmd/Compile.cpp +++ b/tools/aapt2/cmd/Compile.cpp @@ -433,7 +433,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 8d91b0098c1f4..a4610b2575b9c 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 73105e16559bb..5cfbbf2485e08 100644 --- a/tools/aapt2/util/Files.cpp +++ b/tools/aapt2/util/Files.cpp @@ -182,7 +182,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;