Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Don't copy structs to stack in cmpmodes(), use const pointers instead.

(and return 0 immediately if the pointers are the same.)
  • Loading branch information
icculus committed Jul 14, 2013
1 parent fa705d5 commit c8a6ce466fdf65140c788a8a9bcd65ae889b5d96
Showing with 14 additions and 17 deletions.
  1. +14 −17 src/video/SDL_video.c
@@ -360,23 +360,20 @@ SDL_DestroyWindowTexture(_THIS, SDL_Window * window)
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;
}

0 comments on commit c8a6ce4

Please sign in to comment.