Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Don't copy structs to stack in cmpmodes(), use const pointers instead.
Browse files Browse the repository at this point in the history
(and return 0 immediately if the pointers are the same.)
  • Loading branch information
icculus committed Jul 14, 2013
1 parent fa705d5 commit c8a6ce4
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions src/video/SDL_video.c
Expand Up @@ -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;
}
Expand Down

0 comments on commit c8a6ce4

Please sign in to comment.