Don't copy structs to stack in cmpmodes(), use const pointers instead.
authorRyan C. Gordon <icculus@icculus.org>
Sat, 13 Jul 2013 21:50:40 -0400
changeset 7440 9817477202d1
parent 7439 f52afd324ec7
child 7441 468877c2135a
Don't copy structs to stack in cmpmodes(), use const pointers instead. (and return 0 immediately if the pointers are the same.)
src/video/SDL_video.c
--- a/src/video/SDL_video.c	Sat Jul 13 21:42:57 2013 -0400
+++ b/src/video/SDL_video.c	Sat Jul 13 21:50:40 2013 -0400
@@ -360,23 +360,20 @@
 static int
 cmpmodes(const void *A, const void *B)
 {
-    SDL_DisplayMode a = *(const SDL_DisplayMode *) A;
-    SDL_DisplayMode b = *(const SDL_DisplayMode *) B;
-
-    if (a.w != b.w) {
-        return b.w - a.w;
-    }
-    if (a.h != b.h) {
-        return b.h - a.h;
-    }
-    if (SDL_BITSPERPIXEL(a.format) != SDL_BITSPERPIXEL(b.format)) {
-        return SDL_BITSPERPIXEL(b.format) - SDL_BITSPERPIXEL(a.format);
-    }
-    if (SDL_PIXELLAYOUT(a.format) != SDL_PIXELLAYOUT(b.format)) {
-        return SDL_PIXELLAYOUT(b.format) - SDL_PIXELLAYOUT(a.format);
-    }
-    if (a.refresh_rate != b.refresh_rate) {
-        return b.refresh_rate - a.refresh_rate;
+    const SDL_DisplayMode *a = (const SDL_DisplayMode *) A;
+    const SDL_DisplayMode *b = (const SDL_DisplayMode *) B;
+    if (a == b) {
+        return 0;
+    } else if (a->w != b->w) {
+        return b->w - a->w;
+    } else if (a->h != b->h) {
+        return b->h - a->h;
+    } else if (SDL_BITSPERPIXEL(a->format) != SDL_BITSPERPIXEL(b->format)) {
+        return SDL_BITSPERPIXEL(b->format) - SDL_BITSPERPIXEL(a->format);
+    } else if (SDL_PIXELLAYOUT(a->format) != SDL_PIXELLAYOUT(b->format)) {
+        return SDL_PIXELLAYOUT(b->format) - SDL_PIXELLAYOUT(a->format);
+    } else if (a->refresh_rate != b->refresh_rate) {
+        return b->refresh_rate - a->refresh_rate;
     }
     return 0;
 }