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/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) {