Optimized dirty rect code
authorSam Lantinga <slouken@libsdl.org>
Sat, 11 Aug 2007 21:34:08 +0000
changeset 2223175754591a13
parent 2222 926294b2bb4e
child 2224 29cc9e9c76bd
Optimized dirty rect code
src/video/SDL_rect.c
     1.1 --- a/src/video/SDL_rect.c	Sat Aug 11 20:54:31 2007 +0000
     1.2 +++ b/src/video/SDL_rect.c	Sat Aug 11 21:34:08 2007 +0000
     1.3 @@ -122,7 +122,14 @@
     1.4  SDL_AddDirtyRect(SDL_DirtyRectList * list, const SDL_Rect * rect)
     1.5  {
     1.6      SDL_DirtyRect *dirty;
     1.7 -    SDL_DirtyRect *check, *prev, *next;
     1.8 +
     1.9 +    /* FIXME: At what point is this optimization too expensive? */
    1.10 +    for (dirty = list->list; dirty; dirty = dirty->next) {
    1.11 +        if (SDL_HasIntersection(&dirty->rect, rect)) {
    1.12 +            SDL_UnionRect(&dirty->rect, rect, &dirty->rect);
    1.13 +            return;
    1.14 +        }
    1.15 +    }
    1.16  
    1.17      if (list->free) {
    1.18          dirty = list->free;
    1.19 @@ -134,26 +141,6 @@
    1.20          }
    1.21      }
    1.22      dirty->rect = *rect;
    1.23 -
    1.24 -    /* FIXME: At what point is this optimization too expensive? */
    1.25 -    for (prev = NULL, check = list->list; check; check = next) {
    1.26 -        next = check->next;
    1.27 -
    1.28 -        if (SDL_HasIntersection(&dirty->rect, &check->rect)) {
    1.29 -            SDL_UnionRect(&dirty->rect, &check->rect, &dirty->rect);
    1.30 -            if (prev) {
    1.31 -                prev->next = next;
    1.32 -            } else {
    1.33 -                list->list = next;
    1.34 -            }
    1.35 -            check->next = list->free;
    1.36 -            list->free = check;
    1.37 -            --list->count;
    1.38 -        } else {
    1.39 -            prev = check;
    1.40 -        }
    1.41 -    }
    1.42 -
    1.43      dirty->next = list->list;
    1.44      list->list = dirty;
    1.45      ++list->count;
    1.46 @@ -162,12 +149,8 @@
    1.47  void
    1.48  SDL_ClearDirtyRects(SDL_DirtyRectList * list)
    1.49  {
    1.50 -    while (list->list) {
    1.51 -        SDL_DirtyRect *elem = list->list;
    1.52 -        list->list = elem->next;
    1.53 -        elem->next = list->free;
    1.54 -        list->free = elem;
    1.55 -    }
    1.56 +    list->free = list->list;
    1.57 +    list->list = NULL;
    1.58      list->count = 0;
    1.59  }
    1.60