diff options
author | Max Kellermann <max@duempel.org> | 2008-09-19 16:25:28 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-09-19 16:25:28 +0200 |
commit | fac79e52e8347a26f8bbcc9d97d38ee3807d2805 (patch) | |
tree | ba8e71547c8e67c2c1bc9ecbdfa27675f103cf59 /src/screen_browser.c | |
parent | 6bf491217a2543365118839d616933ba43879dda (diff) | |
download | mpd-fac79e52e8347a26f8bbcc9d97d38ee3807d2805.tar.gz mpd-fac79e52e8347a26f8bbcc9d97d38ee3807d2805.tar.xz mpd-fac79e52e8347a26f8bbcc9d97d38ee3807d2805.zip |
filelist: use GPtrArray instead of GList
Since we do a lot of indexed accesses to the filelist, a linked list
doesn't seem appropriate. Use GPtrArray instead.
Diffstat (limited to '')
-rw-r--r-- | src/screen_browser.c | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/src/screen_browser.c b/src/screen_browser.c index b01e70c7a..d2c8aa08e 100644 --- a/src/screen_browser.c +++ b/src/screen_browser.c @@ -40,13 +40,12 @@ static void clear_highlights(mpdclient_filelist_t *fl) { - GList *list = g_list_first(fl->list); + guint i; - while( list ) { - filelist_entry_t *entry = list->data; + for (i = 0; i < filelist_length(fl); ++i) { + struct filelist_entry *entry = filelist_get(fl, i); entry->flags &= ~HIGHLIGHT; - list = list->next; } } @@ -71,13 +70,13 @@ set_highlight(mpdclient_filelist_t *fl, mpd_Song *song, int highlight) void sync_highlights(mpdclient_t *c, mpdclient_filelist_t *fl) { - GList *list = g_list_first(fl->list); + guint i; - while(list) { - filelist_entry_t *entry = list->data; + for (i = 0; i < filelist_length(fl); ++i) { + struct filelist_entry *entry = filelist_get(fl, i); mpd_InfoEntity *entity = entry->entity; - if( entity && entity->type==MPD_INFO_ENTITY_TYPE_SONG ) { + if ( entity && entity->type==MPD_INFO_ENTITY_TYPE_SONG ) { mpd_Song *song = entity->info.song; if( playlist_get_index_from_file(c, song->file) >= 0 ) @@ -85,7 +84,6 @@ sync_highlights(mpdclient_t *c, mpdclient_filelist_t *fl) else entry->flags &= ~HIGHLIGHT; } - list=list->next; } } @@ -125,10 +123,12 @@ browser_lw_callback(unsigned idx, int *highlight, void *data) filelist_entry_t *entry; mpd_InfoEntity *entity; - entry = filelist_get(fl, idx); - if (entry == NULL) + if (idx >= filelist_length(fl)) return NULL; + entry = filelist_get(fl, idx); + assert(entry != NULL); + entity = entry->entity; *highlight = (entry->flags & HIGHLIGHT); @@ -395,21 +395,17 @@ browser_handle_select(struct screen_browser *browser, mpdclient_t *c) void browser_handle_select_all(struct screen_browser *browser, mpdclient_t *c) { - filelist_entry_t *entry; - GList *temp = browser->filelist->list; + guint i; if (browser->filelist == NULL) return; - for (browser->filelist->list = g_list_first(browser->filelist->list); - browser->filelist->list; - browser->filelist->list = g_list_next(browser->filelist->list)) { - entry = browser->filelist->list->data; + for (i = 0; i < filelist_length(browser->filelist); ++i) { + struct filelist_entry *entry = filelist_get(browser->filelist, i); + if (entry != NULL && entry->entity != NULL) browser_select_entry(c, entry, FALSE); } - - browser->filelist->list = temp; } #ifdef HAVE_GETMOUSE |