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>
This commit is contained in:
parent
bcde9eec20
commit
bd3ffa43d2
@ -888,7 +888,7 @@ static bool gather_srcs() {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (auto image : images) {
|
||||
for (const SkString& image : images) {
|
||||
push_codec_srcs(image);
|
||||
}
|
||||
|
||||
@ -897,7 +897,7 @@ static bool gather_srcs() {
|
||||
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));
|
||||
}
|
||||
|
@ -242,7 +242,7 @@ DEF_SIMPLE_GM(all_variants_8888, canvas, 4 * SCALE + 30, 2 * SCALE + 10) {
|
||||
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();
|
||||
|
@ -81,7 +81,7 @@ DEF_SIMPLE_GM(color4f, canvas, 1024, 260) {
|
||||
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));
|
||||
|
@ -340,7 +340,7 @@ DEF_SIMPLE_GM(compare_atlas_vertices, canvas, 560, 585) {
|
||||
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);
|
||||
|
@ -129,7 +129,7 @@ protected:
|
||||
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);
|
||||
|
@ -366,8 +366,8 @@ DEF_SIMPLE_GPU_GM(new_texture_image, context, rtc, canvas, 280, 60) {
|
||||
|
||||
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) {
|
||||
|
@ -218,9 +218,9 @@ protected:
|
||||
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);
|
||||
|
@ -158,7 +158,7 @@ protected:
|
||||
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 @@ protected:
|
||||
};
|
||||
|
||||
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 @@ protected:
|
||||
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) {
|
||||
|
@ -262,7 +262,7 @@ GrDrawOpAtlas::GrDrawOpAtlas(
|
||||
}
|
||||
|
||||
inline void GrDrawOpAtlas::processEviction(PlotLocator plotLocator) {
|
||||
for (auto evictor : fEvictionCallbacks) {
|
||||
for (EvictionCallback* evictor : fEvictionCallbacks) {
|
||||
evictor->evict(plotLocator);
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,7 @@ GrCCPathCache::~GrCCPathCache() {
|
||||
|
||||
// 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::purgeEntriesOlderThan(GrProxyProvider* proxyProvider,
|
||||
}
|
||||
|
||||
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(GrOnFlushResourceProvider* onF
|
||||
}
|
||||
|
||||
void GrCCPathCache::purgeInvalidatedAtlasTextures(GrProxyProvider* proxyProvider) {
|
||||
for (sk_sp<GrTextureProxy>& proxy : fInvalidatedProxies) {
|
||||
for (const sk_sp<GrTextureProxy>& proxy : fInvalidatedProxies) {
|
||||
proxyProvider->removeUniqueKeyFromProxy(proxy.get());
|
||||
}
|
||||
fInvalidatedProxies.reset();
|
||||
|
@ -214,7 +214,7 @@ std::vector<GrCaps::TestFormatColorTypeCombination> GrDawnCaps::getTestingCombin
|
||||
};
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
for (auto combo : combos) {
|
||||
for (const GrCaps::TestFormatColorTypeCombination& combo : combos) {
|
||||
SkASSERT(this->onAreColorTypeAndFormatCompatible(combo.fColorType, combo.fFormat));
|
||||
}
|
||||
#endif
|
||||
|
@ -75,7 +75,7 @@ std::vector<GrCaps::TestFormatColorTypeCombination> GrMockCaps::getTestingCombin
|
||||
};
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
for (auto combo : combos) {
|
||||
for (const GrCaps::TestFormatColorTypeCombination& combo : combos) {
|
||||
SkASSERT(this->onAreColorTypeAndFormatCompatible(combo.fColorType, combo.fFormat));
|
||||
}
|
||||
#endif
|
||||
|
@ -325,7 +325,7 @@ public:
|
||||
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) {
|
||||
|
@ -184,7 +184,7 @@ void SkPDF::AttributeList::appendStringArray(
|
||||
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));
|
||||
|
@ -75,9 +75,9 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CopySurface, reporter, ctxInfo) {
|
||||
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);
|
||||
|
@ -105,9 +105,9 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(GrSurfaceRenderability, reporter, ctxInfo) {
|
||||
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 @@ DEF_GPUTEST(InitialTextureClear, reporter, baseOptions) {
|
||||
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());
|
||||
|
@ -456,7 +456,7 @@ static void test_linear_fuzzer(skiatest::Reporter*) {
|
||||
|
||||
SkPaint paint;
|
||||
|
||||
for (auto colorSpace : colorSpaces) {
|
||||
for (const SkColorSpace* colorSpace : colorSpaces) {
|
||||
|
||||
sk_sp<SkSurface> surface = SkSurface::MakeRaster(SkImageInfo::Make(100, 100,
|
||||
kN32_SkColorType,
|
||||
|
@ -393,7 +393,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_makeTextureImage, reporter, contextIn
|
||||
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 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_makeNonTextureImage, reporter, contex
|
||||
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 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(makeBackendTexture, reporter, ctxInfo) {
|
||||
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 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(makeBackendTexture, reporter, ctxInfo) {
|
||||
{ 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!");
|
||||
|
@ -263,7 +263,7 @@ DEF_GPUTEST(PromiseImageTextureShutdown, reporter, ctxInfo) {
|
||||
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) {
|
||||
|
@ -565,11 +565,11 @@ DEF_TEST(ReadPixels_ValidConversion, reporter) {
|
||||
};
|
||||
|
||||
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));
|
||||
|
@ -20,7 +20,7 @@ DEF_TEST(SkColorSpaceXformSteps, r) {
|
||||
opaque = kOpaque_SkAlphaType,
|
||||
unpremul = kUnpremul_SkAlphaType;
|
||||
|
||||
struct {
|
||||
struct Test {
|
||||
sk_sp<SkColorSpace> src, dst;
|
||||
SkAlphaType srcAT, dstAT;
|
||||
|
||||
@ -30,7 +30,8 @@ DEF_TEST(SkColorSpaceXformSteps, r) {
|
||||
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 @@ DEF_TEST(SkColorSpaceXformSteps, r) {
|
||||
};
|
||||
|
||||
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);
|
||||
|
@ -90,10 +90,12 @@ DEF_TEST(StreamBuffer, r) {
|
||||
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 @@ DEF_TEST(StreamBuffer, r) {
|
||||
: std::make_unique<SkFILEStream>(path.c_str()); }, true },
|
||||
};
|
||||
|
||||
for (auto f : factories) {
|
||||
for (const Factory& f : factories) {
|
||||
if (tmpDir.isEmpty() && f.skipIfNoTmpDir) {
|
||||
continue;
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ void SkSLSlide::draw(SkCanvas* canvas) {
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
|
Loading…
Reference in New Issue
Block a user