Fix range-based for loops which copy the loop variable unnecessarily.
This will allow us to enable the ClangTidy check
performance-for-range-copy.
Change-Id: I11f152ffe458f5f353da8715ffd2fd47cf4e71a7
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/306946
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
diff --git a/dm/DM.cpp b/dm/DM.cpp
index 043d00b..e055b83 100644
--- a/dm/DM.cpp
+++ b/dm/DM.cpp
@@ -888,7 +888,7 @@
return false;
}
- for (auto image : images) {
+ for (const SkString& image : images) {
push_codec_srcs(image);
}
@@ -897,7 +897,7 @@
return false;
}
- for (auto colorImage : colorImages) {
+ for (const SkString& colorImage : colorImages) {
push_src("colorImage", "decode_native", new ColorCodecSrc(colorImage, false));
push_src("colorImage", "decode_to_dst", new ColorCodecSrc(colorImage, true));
}
diff --git a/gm/all_bitmap_configs.cpp b/gm/all_bitmap_configs.cpp
index 0d808e2..3b3dfb2 100644
--- a/gm/all_bitmap_configs.cpp
+++ b/gm/all_bitmap_configs.cpp
@@ -242,7 +242,7 @@
SkColorSpace::MakeSRGB(),
nullptr,
};
- for (auto colorSpace : colorSpaces) {
+ for (const sk_sp<SkColorSpace>& colorSpace : colorSpaces) {
canvas->save();
for (auto alphaType : {kPremul_SkAlphaType, kUnpremul_SkAlphaType}) {
canvas->save();
diff --git a/gm/color4f.cpp b/gm/color4f.cpp
index 8a99c14..3b9dfe4 100644
--- a/gm/color4f.cpp
+++ b/gm/color4f.cpp
@@ -81,7 +81,7 @@
nullptr,
SkColorSpace::MakeSRGB()
};
- for (auto colorSpace : colorSpaces) {
+ for (const sk_sp<SkColorSpace>& colorSpace : colorSpaces) {
const SkImageInfo info = SkImageInfo::Make(1024, 100, kN32_SkColorType, kPremul_SkAlphaType,
colorSpace);
auto surface(SkSurface::MakeRaster(info));
diff --git a/gm/drawatlas.cpp b/gm/drawatlas.cpp
index 1c70e7e..2ea54bb 100644
--- a/gm/drawatlas.cpp
+++ b/gm/drawatlas.cpp
@@ -340,7 +340,7 @@
for (float alpha : { 1.0f, 0.5f }) {
paint.setAlphaf(alpha);
canvas->save();
- for (auto cf : filters) {
+ for (const sk_sp<SkColorFilter>& cf : filters) {
paint.setColorFilter(cf);
canvas->drawAtlas(image, &xform, &tex, &color, 1,
mode, &tex, &paint);
diff --git a/gm/encode_srgb.cpp b/gm/encode_srgb.cpp
index 0db8dc1..380bb7f 100644
--- a/gm/encode_srgb.cpp
+++ b/gm/encode_srgb.cpp
@@ -129,7 +129,7 @@
for (SkColorType colorType : colorTypes) {
for (SkAlphaType alphaType : alphaTypes) {
canvas->save();
- for (sk_sp<SkColorSpace> colorSpace : colorSpaces) {
+ for (const sk_sp<SkColorSpace>& colorSpace : colorSpaces) {
make(&bitmap, colorType, alphaType, colorSpace);
auto image = SkImage::MakeFromEncoded(encode_data(bitmap, fEncodedFormat));
canvas->drawImage(image.get(), 0.0f, 0.0f);
diff --git a/gm/image.cpp b/gm/image.cpp
index c4c417d..2d66e86 100644
--- a/gm/image.cpp
+++ b/gm/image.cpp
@@ -366,8 +366,8 @@
constexpr SkScalar kPad = 5.f;
canvas->translate(kPad, kPad);
- for (auto factory : imageFactories) {
- auto image(factory());
+ for (const auto& factory : imageFactories) {
+ sk_sp<SkImage> image(factory());
if (image) {
sk_sp<SkImage> texImage(image->makeTextureImage(direct));
if (texImage) {
diff --git a/gm/patheffects.cpp b/gm/patheffects.cpp
index 695d5e2..7d82f85 100644
--- a/gm/patheffects.cpp
+++ b/gm/patheffects.cpp
@@ -218,9 +218,9 @@
paint.setColor(0xFF8888FF);
paint.setAntiAlias(true);
- for (auto& path : { path0, path1 }) {
+ for (const SkPath& path : { path0, path1 }) {
canvas->save();
- for (auto pe : effects) {
+ for (const sk_sp<SkPathEffect>& pe : effects) {
paint.setPathEffect(pe);
canvas->drawPath(path, paint);
canvas->drawPath(path, wireframe);
diff --git a/gm/readpixels.cpp b/gm/readpixels.cpp
index 1fad98f..6095865 100644
--- a/gm/readpixels.cpp
+++ b/gm/readpixels.cpp
@@ -158,7 +158,7 @@
make_small_gamut(),
};
- for (sk_sp<SkColorSpace> dstColorSpace : colorSpaces) {
+ for (const sk_sp<SkColorSpace>& dstColorSpace : colorSpaces) {
for (SkColorType srcColorType : colorTypes) {
canvas->save();
sk_sp<SkImage> image = make_raster_image(srcColorType);
@@ -227,7 +227,7 @@
};
sk_sp<SkImage> image = make_codec_image();
- for (sk_sp<SkColorSpace> dstColorSpace : colorSpaces) {
+ for (const sk_sp<SkColorSpace>& dstColorSpace : colorSpaces) {
canvas->save();
for (SkColorType dstColorType : colorTypes) {
for (SkAlphaType dstAlphaType : alphaTypes) {
@@ -293,8 +293,8 @@
SkImage::kDisallow_CachingHint,
};
- for (sk_sp<SkImage> image : images) {
- for (sk_sp<SkColorSpace> dstColorSpace : colorSpaces) {
+ for (const sk_sp<SkImage>& image : images) {
+ for (const sk_sp<SkColorSpace>& dstColorSpace : colorSpaces) {
canvas->save();
for (SkColorType dstColorType : colorTypes) {
for (SkAlphaType dstAlphaType : alphaTypes) {
diff --git a/src/gpu/GrDrawOpAtlas.cpp b/src/gpu/GrDrawOpAtlas.cpp
index ffea3e1..39bb49b 100644
--- a/src/gpu/GrDrawOpAtlas.cpp
+++ b/src/gpu/GrDrawOpAtlas.cpp
@@ -262,7 +262,7 @@
}
inline void GrDrawOpAtlas::processEviction(PlotLocator plotLocator) {
- for (auto evictor : fEvictionCallbacks) {
+ for (EvictionCallback* evictor : fEvictionCallbacks) {
evictor->evict(plotLocator);
}
diff --git a/src/gpu/ccpr/GrCCPathCache.cpp b/src/gpu/ccpr/GrCCPathCache.cpp
index b1037bb..cb86b55 100644
--- a/src/gpu/ccpr/GrCCPathCache.cpp
+++ b/src/gpu/ccpr/GrCCPathCache.cpp
@@ -106,7 +106,7 @@
// Now take all the atlas textures we just invalidated and purge them from the GrResourceCache.
// We just purge via message bus since we don't have any access to the resource cache right now.
- for (sk_sp<GrTextureProxy>& proxy : fInvalidatedProxies) {
+ for (const sk_sp<GrTextureProxy>& proxy : fInvalidatedProxies) {
SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(
GrUniqueKeyInvalidatedMessage(proxy->getUniqueKey(), fContextUniqueID));
}
@@ -295,7 +295,7 @@
}
void GrCCPathCache::purgeInvalidatedAtlasTextures(GrOnFlushResourceProvider* onFlushRP) {
- for (sk_sp<GrTextureProxy>& proxy : fInvalidatedProxies) {
+ for (const sk_sp<GrTextureProxy>& proxy : fInvalidatedProxies) {
onFlushRP->removeUniqueKeyFromProxy(proxy.get());
}
fInvalidatedProxies.reset();
@@ -307,7 +307,7 @@
}
void GrCCPathCache::purgeInvalidatedAtlasTextures(GrProxyProvider* proxyProvider) {
- for (sk_sp<GrTextureProxy>& proxy : fInvalidatedProxies) {
+ for (const sk_sp<GrTextureProxy>& proxy : fInvalidatedProxies) {
proxyProvider->removeUniqueKeyFromProxy(proxy.get());
}
fInvalidatedProxies.reset();
diff --git a/src/gpu/dawn/GrDawnCaps.cpp b/src/gpu/dawn/GrDawnCaps.cpp
index eeea8eb..eddad52 100644
--- a/src/gpu/dawn/GrDawnCaps.cpp
+++ b/src/gpu/dawn/GrDawnCaps.cpp
@@ -214,7 +214,7 @@
};
#ifdef SK_DEBUG
- for (auto combo : combos) {
+ for (const GrCaps::TestFormatColorTypeCombination& combo : combos) {
SkASSERT(this->onAreColorTypeAndFormatCompatible(combo.fColorType, combo.fFormat));
}
#endif
diff --git a/src/gpu/mock/GrMockCaps.cpp b/src/gpu/mock/GrMockCaps.cpp
index de9e39b..cdf9d9f 100644
--- a/src/gpu/mock/GrMockCaps.cpp
+++ b/src/gpu/mock/GrMockCaps.cpp
@@ -75,7 +75,7 @@
};
#ifdef SK_DEBUG
- for (auto combo : combos) {
+ for (const GrCaps::TestFormatColorTypeCombination& combo : combos) {
SkASSERT(this->onAreColorTypeAndFormatCompatible(combo.fColorType, combo.fFormat));
}
#endif
diff --git a/src/pathops/SkPathOpsAsWinding.cpp b/src/pathops/SkPathOpsAsWinding.cpp
index 763427f..500dc35 100644
--- a/src/pathops/SkPathOpsAsWinding.cpp
+++ b/src/pathops/SkPathOpsAsWinding.cpp
@@ -325,7 +325,7 @@
SkPathPriv::Iterate iterate(fPath);
auto iter = iterate.begin();
int verbCount = 0;
- for (auto contour : contours) {
+ for (const Contour& contour : contours) {
SkPath reverse;
SkPath* temp = contour.fReverse ? &reverse : result;
for (; iter != iterate.end() && verbCount < contour.fVerbEnd; ++iter, ++verbCount) {
diff --git a/src/pdf/SkPDFTag.cpp b/src/pdf/SkPDFTag.cpp
index 3b6688d..5cb7da2 100644
--- a/src/pdf/SkPDFTag.cpp
+++ b/src/pdf/SkPDFTag.cpp
@@ -184,7 +184,7 @@
std::unique_ptr<SkPDFDict> attrDict = SkPDFMakeDict();
attrDict->insertName("O", owner);
std::unique_ptr<SkPDFArray> pdfArray = SkPDFMakeArray();
- for (SkString element : values) {
+ for (const SkString& element : values) {
pdfArray->appendString(element);
}
attrDict->insertObject(name, std::move(pdfArray));
diff --git a/tests/CopySurfaceTest.cpp b/tests/CopySurfaceTest.cpp
index 2780daf..58ca6cc 100644
--- a/tests/CopySurfaceTest.cpp
+++ b/tests/CopySurfaceTest.cpp
@@ -75,9 +75,9 @@
for (auto dOrigin : {kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin}) {
for (auto sRenderable : {GrRenderable::kYes, GrRenderable::kNo}) {
for (auto dRenderable : {GrRenderable::kYes, GrRenderable::kNo}) {
- for (auto srcRect : kSrcRects) {
- for (auto dstPoint : kDstPoints) {
- for (auto ii: kImageInfos) {
+ for (const SkIRect& srcRect : kSrcRects) {
+ for (const SkIPoint& dstPoint : kDstPoints) {
+ for (const SkImageInfo& ii: kImageInfos) {
auto src = sk_gpu_test::MakeTextureProxyFromData(
direct, sRenderable, sOrigin, ii, srcPixels.get(),
kRowBytes);
diff --git a/tests/GrSurfaceTest.cpp b/tests/GrSurfaceTest.cpp
index 216ce0e..fc9bb63 100644
--- a/tests/GrSurfaceTest.cpp
+++ b/tests/GrSurfaceTest.cpp
@@ -105,9 +105,9 @@
static constexpr SkISize kDims = {64, 64};
const std::vector<GrCaps::TestFormatColorTypeCombination>& combos =
- caps->getTestingCombinations();
+ caps->getTestingCombinations();
- for (auto combo : combos) {
+ for (const GrCaps::TestFormatColorTypeCombination& combo : combos) {
SkASSERT(combo.fColorType != GrColorType::kUnknown);
SkASSERT(combo.fFormat.isValid());
@@ -209,9 +209,9 @@
const GrCaps* caps = context->priv().caps();
const std::vector<GrCaps::TestFormatColorTypeCombination>& combos =
- caps->getTestingCombinations();
+ caps->getTestingCombinations();
- for (auto combo : combos) {
+ for (const GrCaps::TestFormatColorTypeCombination& combo : combos) {
SkASSERT(combo.fColorType != GrColorType::kUnknown);
SkASSERT(combo.fFormat.isValid());
diff --git a/tests/GradientTest.cpp b/tests/GradientTest.cpp
index 7d2b5e5..ba80793 100644
--- a/tests/GradientTest.cpp
+++ b/tests/GradientTest.cpp
@@ -456,7 +456,7 @@
SkPaint paint;
- for (auto colorSpace : colorSpaces) {
+ for (const SkColorSpace* colorSpace : colorSpaces) {
sk_sp<SkSurface> surface = SkSurface::MakeRaster(SkImageInfo::Make(100, 100,
kN32_SkColorType,
diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp
index ef25c61..1340d64 100644
--- a/tests/ImageTest.cpp
+++ b/tests/ImageTest.cpp
@@ -393,7 +393,7 @@
return otherContextImage;
}};
for (auto mipMapped : {GrMipmapped::kNo, GrMipmapped::kYes}) {
- for (auto factory : imageFactories) {
+ for (const auto& factory : imageFactories) {
sk_sp<SkImage> image(factory());
if (!image) {
ERRORF(reporter, "Error creating image.");
@@ -458,7 +458,7 @@
create_picture_image,
[context] { return create_gpu_image(context); },
};
- for (auto factory : imageFactories) {
+ for (const auto& factory : imageFactories) {
sk_sp<SkImage> image = factory();
if (!image->isTextureBacked()) {
REPORTER_ASSERT(reporter, image->makeNonTextureImage().get() == image.get());
@@ -1064,11 +1064,12 @@
auto createLarge = [context] {
return create_image_large(context->priv().caps()->maxTextureSize());
};
- struct {
- std::function<sk_sp<SkImage> ()> fImageFactory;
- bool fExpectation;
- bool fCanTakeDirectly;
- } testCases[] = {
+ struct TestCase {
+ std::function<sk_sp<SkImage>()> fImageFactory;
+ bool fExpectation;
+ bool fCanTakeDirectly;
+ };
+ TestCase testCases[] = {
{ create_image, true, false },
{ create_codec_image, true, false },
{ create_data_image, true, false },
@@ -1085,7 +1086,7 @@
{ createLarge, false, false }
};
- for (auto testCase : testCases) {
+ for (const TestCase& testCase : testCases) {
sk_sp<SkImage> image(testCase.fImageFactory());
if (!image) {
ERRORF(reporter, "Failed to create image!");
diff --git a/tests/PromiseImageTest.cpp b/tests/PromiseImageTest.cpp
index 3a41b62..126b44b 100644
--- a/tests/PromiseImageTest.cpp
+++ b/tests/PromiseImageTest.cpp
@@ -263,7 +263,7 @@
continue;
}
DeathFn contextKillers[] = {destroy, abandon, releaseResourcesAndAbandon};
- for (auto contextDeath : contextKillers) {
+ for (const DeathFn& contextDeath : contextKillers) {
sk_gpu_test::GrContextFactory factory;
auto ctx = factory.get(contextType);
if (!ctx) {
diff --git a/tests/ReadPixelsTest.cpp b/tests/ReadPixelsTest.cpp
index 60f1e1e..490edac 100644
--- a/tests/ReadPixelsTest.cpp
+++ b/tests/ReadPixelsTest.cpp
@@ -565,11 +565,11 @@
};
for (SkColorType dstCT : kColorTypes) {
- for (SkAlphaType dstAT: kAlphaTypes) {
- for (sk_sp<SkColorSpace> dstCS : kColorSpaces) {
+ for (SkAlphaType dstAT : kAlphaTypes) {
+ for (const sk_sp<SkColorSpace>& dstCS : kColorSpaces) {
for (SkColorType srcCT : kColorTypes) {
- for (SkAlphaType srcAT: kAlphaTypes) {
- for (sk_sp<SkColorSpace> srcCS : kColorSpaces) {
+ for (SkAlphaType srcAT : kAlphaTypes) {
+ for (const sk_sp<SkColorSpace>& srcCS : kColorSpaces) {
test_conversion(reporter,
SkImageInfo::Make(kNumPixels, 1, dstCT, dstAT, dstCS),
SkImageInfo::Make(kNumPixels, 1, srcCT, srcAT, srcCS));
diff --git a/tests/SkColorSpaceXformStepsTest.cpp b/tests/SkColorSpaceXformStepsTest.cpp
index c3308ab..d89a8da 100644
--- a/tests/SkColorSpaceXformStepsTest.cpp
+++ b/tests/SkColorSpaceXformStepsTest.cpp
@@ -20,7 +20,7 @@
opaque = kOpaque_SkAlphaType,
unpremul = kUnpremul_SkAlphaType;
- struct {
+ struct Test {
sk_sp<SkColorSpace> src, dst;
SkAlphaType srcAT, dstAT;
@@ -30,7 +30,8 @@
bool encode;
bool premul;
- } tests[] = {
+ };
+ Test tests[] = {
// The general case is converting between two color spaces with different gamuts
// and different transfer functions. There's no optimization possible here.
{ adobe, srgb, premul, premul,
@@ -130,7 +131,7 @@
};
uint32_t tested = 0x00000000;
- for (auto t : tests) {
+ for (const Test& t : tests) {
SkColorSpaceXformSteps steps{t.src.get(), t.srcAT,
t.dst.get(), t.dstAT};
REPORTER_ASSERT(r, steps.flags.unpremul == t.unpremul);
diff --git a/tests/StreamBufferTest.cpp b/tests/StreamBufferTest.cpp
index ce3c5f9..a6b71f6 100644
--- a/tests/StreamBufferTest.cpp
+++ b/tests/StreamBufferTest.cpp
@@ -90,10 +90,12 @@
writer.write(gText, size);
}
- struct {
+ struct Factory {
std::function<std::unique_ptr<SkStream>()> createStream;
bool skipIfNoTmpDir;
- } factories[] = {
+ };
+
+ Factory factories[] = {
{ [&data]() { return std::make_unique<SkMemoryStream>(data); }, false },
{ [&data]() { return std::make_unique<NotAssetMemStream>(data); }, false },
{ [&path]() { return path.isEmpty()
@@ -101,7 +103,7 @@
: std::make_unique<SkFILEStream>(path.c_str()); }, true },
};
- for (auto f : factories) {
+ for (const Factory& f : factories) {
if (tmpDir.isEmpty() && f.skipIfNoTmpDir) {
continue;
}
diff --git a/tools/viewer/SkSLSlide.cpp b/tools/viewer/SkSLSlide.cpp
index 00f0a14..94edbbe 100644
--- a/tools/viewer/SkSLSlide.cpp
+++ b/tools/viewer/SkSLSlide.cpp
@@ -162,7 +162,7 @@
}
}
- for (const auto [i, name] : SkMakeEnumerate(fEffect->children())) {
+ for (const auto& [i, name] : SkMakeEnumerate(fEffect->children())) {
auto curShader = std::find_if(fShaders.begin(), fShaders.end(),
[tgt = fChildren[i]](auto p) { return p.second == tgt; });
SkASSERT(curShader!= fShaders.end());