summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-06-08 12:34:18 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-06-08 12:42:51 -0700
commita55411c55894f4c238598c9ad93d9e20604f8bdd (patch)
tree28e969349bb3b7f08bf4d9dbf093eb6e3743e0d1
parentf037f03268f2676bf906f19353871186af297d12 (diff)
downloadsubsurface-a55411c55894f4c238598c9ad93d9e20604f8bdd.tar.gz
Picture handling: keep picture list sorted
And simplify the list handling algorithm. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--dive.c18
-rw-r--r--dive.h2
2 files changed, 9 insertions, 11 deletions
diff --git a/dive.c b/dive.c
index 5c9d3664d..a04c92198 100644
--- a/dive.c
+++ b/dive.c
@@ -2294,16 +2294,14 @@ void dive_create_picture(struct dive *d, char *filename, int shift_time)
dive_set_geodata_from_picture(d, p);
}
-void dive_add_picture(struct dive *d, struct picture *picture)
-{
- if (d->picture_list == NULL) {
- d->picture_list = picture;
- return;
- }
- struct picture *last = d->picture_list;
- while( last->next )
- last = last->next;
- last->next = picture;
+void dive_add_picture(struct dive *d, struct picture *newpic)
+{
+ struct picture **pic_ptr = &d->picture_list;
+ /* let's keep the list sorted by time */
+ while( *pic_ptr && (*pic_ptr)->timestamp < newpic->timestamp )
+ pic_ptr = &(*pic_ptr)->next;
+ newpic->next = *pic_ptr;
+ *pic_ptr = newpic;
return;
}
diff --git a/dive.h b/dive.h
index be6edfc31..279a2944c 100644
--- a/dive.h
+++ b/dive.h
@@ -302,7 +302,7 @@ struct picture {
extern struct picture *alloc_picture();
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 unsigned int dive_get_picture_count(struct dive *d);
extern void picture_load_exif_data(struct picture *p);