Use std::swap instead of temporary values
authorArkadiy Illarionov <qarkai@gmail.com>
Sun, 10 Mar 2024 11:57:45 +0000 (14:57 +0300)
committerColin Clark <colin.clark@cclark.uk>
Sun, 10 Mar 2024 14:44:38 +0000 (14:44 +0000)
src/collect-table.cc
src/collect.cc
src/filedata.cc
src/layout.cc
src/pixbuf-util.cc
src/renderer-tiles.cc
src/slideshow.cc
src/view-file/view-file-icon.cc

index 874d15d..0d3016f 100644 (file)
@@ -22,6 +22,7 @@
 #include "collect-table.h"
 
 #include <cstddef>
+#include <utility>
 
 #include <cairo.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
@@ -511,7 +512,6 @@ static void collection_table_select_region_util(CollectTable *ct, CollectInfo *s
        gint col1;
        gint row2;
        gint col2;
-       gint t;
        gint i;
        gint j;
 
@@ -548,15 +548,11 @@ static void collection_table_select_region_util(CollectTable *ct, CollectInfo *s
 
        if (row2 < row1)
                {
-               t = row1;
-               row1 = row2;
-               row2 = t;
+               std::swap(row1, row2);
                }
        if (col2 < col1)
                {
-               t = col1;
-               col1 = col2;
-               col2 = t;
+               std::swap(col1, col2);
                }
 
        DEBUG_1("table: %d x %d to %d x %d", row1, col1, row2, col2);
index 2f7ca47..5b9a62f 100644 (file)
@@ -26,6 +26,7 @@
 #include <cstdlib>
 #include <cstring>
 #include <ctime>
+#include <utility>
 
 #include <glib-object.h>
 
@@ -214,7 +215,6 @@ GList *collection_list_randomize(GList *list)
        guint random;
        guint length;
        guint i;
-       gpointer tmp;
        GList *nlist;
        GList *olist;
 
@@ -228,9 +228,7 @@ GList *collection_list_randomize(GList *list)
                random = static_cast<guint>(1.0 * length * rand()/(RAND_MAX + 1.0));
                olist = g_list_nth(list, i);
                nlist = g_list_nth(list, random);
-               tmp = olist->data;
-               olist->data = nlist->data;
-               nlist->data = tmp;
+               std::swap(olist->data, nlist->data);
                }
 
        return list;
index d66e80b..c0a04ab 100644 (file)
@@ -30,6 +30,7 @@
 #include <cstdlib>
 #include <cstring>
 #include <ctime>
+#include <utility>
 
 #include <glib-object.h>
 #include <grp.h>
@@ -1171,9 +1172,7 @@ gint filelist_sort_compare_filedata(FileData *fa, FileData *fb)
        gint ret;
        if (!filelist_sort_ascend)
                {
-               FileData *tmp = fa;
-               fa = fb;
-               fb = tmp;
+               std::swap(fa, fb);
                }
 
        switch (filelist_sort_method)
index c478a79..f955399 100644 (file)
@@ -24,6 +24,7 @@
 #include <unistd.h>
 
 #include <cstring>
+#include <utility>
 
 #include <gdk-pixbuf/gdk-pixbuf.h>
 #include <gdk/gdk.h>
@@ -1915,11 +1916,7 @@ static void layout_grid_setup(LayoutWindow *lw)
 
        if (!layout_location_vertical(static_cast<LayoutLocation>(priority_location)))
                {
-               GtkWidget *tmp;
-
-               tmp = v;
-               v = h;
-               h = tmp;
+               std::swap(v, h);
                }
 
        gq_gtk_box_pack_start(GTK_BOX(lw->group_box), v, TRUE, TRUE, 0);
index 35abc2f..0d87b7f 100644 (file)
@@ -25,6 +25,7 @@
 #include <cmath>
 #include <cstdlib>
 #include <cstring>
+#include <utility>
 
 #include <cairo.h>
 #include <gio/gio.h>
@@ -1044,7 +1045,6 @@ void pixbuf_draw_triangle(GdkPixbuf *pb,
        gint slope1_x;
        gint slope1_y;
        gint y;
-       gint t;
        gboolean middle = FALSE;
 
        if (!pb) return;
@@ -1073,18 +1073,18 @@ void pixbuf_draw_triangle(GdkPixbuf *pb,
 
        if (y1 > y2)
                {
-               t = x1; x1 = x2; x2 = t;
-               t = y1; y1 = y2; y2 = t;
+               std::swap(x1, x2);
+               std::swap(y1, y2);
                }
        if (y2 > y3)
                {
-               t = x2; x2 = x3; x3 = t;
-               t = y2; y2 = y3; y3 = t;
+               std::swap(x2, x3);
+               std::swap(y2, y3);
                }
        if (y1 > y2)
                {
-               t = x1; x1 = x2; x2 = t;
-               t = y1; y1 = y2; y2 = t;
+               std::swap(x1, x2);
+               std::swap(y1, y2);
                }
 
        slope1 = static_cast<gdouble>(y2 - y1);
@@ -1114,7 +1114,7 @@ void pixbuf_draw_triangle(GdkPixbuf *pb,
 
                if (xa > xb)
                        {
-                       t = xa; xa = xb; xb = t;
+                       std::swap(xa, xb);
                        }
 
                xa = CLAMP(xa, fx1, fx2);
@@ -1149,10 +1149,8 @@ static gboolean util_clip_line(gdouble clip_x, gdouble clip_y, gdouble clip_w, g
 
        if (x1 > x2)
                {
-               gdouble t;
-
-               t = x1; x1 = x2; x2 = t;
-               t = y1; y1 = y2; y2 = t;
+               std::swap(x1, x2);
+               std::swap(y1, y2);
                flip = TRUE;
                }
 
@@ -1191,12 +1189,10 @@ static gboolean util_clip_line(gdouble clip_x, gdouble clip_y, gdouble clip_w, g
                }
        else
                {
-               gdouble t;
-
                if (y1 < clip_y || y2 > clip_y + clip_h) return FALSE;
 
-               t = x1; x1 = x2; x2 = t;
-               t = y1; y1 = y2; y2 = t;
+               std::swap(x1, x2);
+               std::swap(y1, y2);
                flip = !flip;
                }
 
@@ -1293,9 +1289,8 @@ void pixbuf_draw_line(GdkPixbuf *pb,
                {
                if (rx1 > rx2)
                        {
-                       gdouble t;
-                       t = rx1; rx1 = rx2; rx2 = t;
-                       t = ry1; ry1 = ry2; ry2 = t;
+                       std::swap(rx1, rx2);
+                       std::swap(ry1, ry2);
                        }
 
                slope = rx2 - rx1;
@@ -1320,9 +1315,8 @@ void pixbuf_draw_line(GdkPixbuf *pb,
                {
                if (ry1 > ry2)
                        {
-                       gdouble t;
-                       t = rx1; rx1 = rx2; rx2 = t;
-                       t = ry1; ry1 = ry2; ry2 = t;
+                       std::swap(rx1, rx2);
+                       std::swap(ry1, ry2);
                        }
 
                slope = ry2 - ry1;
index bb85977..5e3068c 100644 (file)
@@ -24,6 +24,7 @@
 #include <cmath>
 #include <cstdlib>
 #include <cstring>
+#include <utility>
 
 #include <cairo.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
@@ -1512,14 +1513,11 @@ static void rt_tile_render(RendererTiles *rt, ImageTile *it,
 
                switch (orientation)
                        {
-                       gdouble tmp;
                        case EXIF_ORIENTATION_LEFT_TOP:
                        case EXIF_ORIENTATION_RIGHT_TOP:
                        case EXIF_ORIENTATION_RIGHT_BOTTOM:
                        case EXIF_ORIENTATION_LEFT_BOTTOM:
-                               tmp = scale_x;
-                               scale_x = scale_y;
-                               scale_y = tmp;
+                               std::swap(scale_x, scale_y);
                                break;
                        default:
                                /* nothing to do */
index 65e48f1..56934be 100644 (file)
@@ -22,6 +22,7 @@
 #include "slideshow.h"
 
 #include <cstdlib>
+#include <utility>
 
 #include "collect.h"
 #include "filedata.h"
@@ -93,21 +94,13 @@ static GPtrArray *generate_ptr_array_from_list(GList *src_list)
        return arr;
 }
 
-static void swap(GPtrArray *array, guint index1, guint index2)
-{
-       gpointer temp = g_ptr_array_index(array, index1);
-
-       g_ptr_array_index(array, index1) = g_ptr_array_index(array, index2);
-       g_ptr_array_index(array, index2) = temp;
-}
-
 static void ptr_array_random_shuffle(GPtrArray *array)
 {
        guint i;
        for (i = 0; i < array->len; ++i)
                {
                guint p = static_cast<double>(rand()) / (static_cast<double>(RAND_MAX) + 1.0) * array->len;
-               swap(array, i, p);
+               std::swap(g_ptr_array_index(array, i), g_ptr_array_index(array, p));
                }
 }
 
index 1a61eac..fe7c180 100644 (file)
@@ -22,6 +22,7 @@
 #include "view-file-icon.h"
 
 #include <cstring>
+#include <utility>
 
 #include <glib-object.h>
 
@@ -772,7 +773,6 @@ static void vficon_select_region_util(ViewFile *vf, FileData *start, FileData *e
        gint col1;
        gint row2;
        gint col2;
-       gint t;
        gint i;
        gint j;
 
@@ -787,9 +787,7 @@ static void vficon_select_region_util(ViewFile *vf, FileData *start, FileData *e
 
                if (g_list_index(vf->list, start) > g_list_index(vf->list, end))
                        {
-                       FileData *tmp = start;
-                       start = end;
-                       end = tmp;
+                       std::swap(start, end);
                        }
 
                work = g_list_find(vf->list, start);
@@ -809,15 +807,11 @@ static void vficon_select_region_util(ViewFile *vf, FileData *start, FileData *e
        // rectangular_selection==true.
        if (row2 < row1)
                {
-               t = row1;
-               row1 = row2;
-               row2 = t;
+               std::swap(row1, row2);
                }
        if (col2 < col1)
                {
-               t = col1;
-               col1 = col2;
-               col2 = t;
+               std::swap(col1, col2);
                }
 
        DEBUG_1("table: %d x %d to %d x %d", row1, col1, row2, col2);