Picture handling: keep picture list sorted

And simplify the list handling algorithm.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2014-06-08 12:34:18 -07:00
parent f037f03268
commit a55411c558
2 changed files with 8 additions and 10 deletions

16
dive.c
View file

@ -2294,16 +2294,14 @@ void dive_create_picture(struct dive *d, char *filename, int shift_time)
dive_set_geodata_from_picture(d, p); dive_set_geodata_from_picture(d, p);
} }
void dive_add_picture(struct dive *d, struct picture *picture) void dive_add_picture(struct dive *d, struct picture *newpic)
{ {
if (d->picture_list == NULL) { struct picture **pic_ptr = &d->picture_list;
d->picture_list = picture; /* let's keep the list sorted by time */
return; while( *pic_ptr && (*pic_ptr)->timestamp < newpic->timestamp )
} pic_ptr = &(*pic_ptr)->next;
struct picture *last = d->picture_list; newpic->next = *pic_ptr;
while( last->next ) *pic_ptr = newpic;
last = last->next;
last->next = picture;
return; return;
} }

2
dive.h
View file

@ -302,7 +302,7 @@ struct picture {
extern struct picture *alloc_picture(); extern struct picture *alloc_picture();
extern void dive_create_picture(struct dive *d, char *filename, int shift_time); extern void dive_create_picture(struct dive *d, char *filename, int shift_time);
extern void dive_add_picture(struct dive *d, struct picture *pic); extern void dive_add_picture(struct dive *d, struct picture *newpic);
extern void dive_remove_picture(struct dive *d, struct picture *pic); extern void dive_remove_picture(struct dive *d, struct picture *pic);
extern unsigned int dive_get_picture_count(struct dive *d); extern unsigned int dive_get_picture_count(struct dive *d);
extern void picture_load_exif_data(struct picture *p); extern void picture_load_exif_data(struct picture *p);