From 21b1550739b9a3fe4ab27cabd4a8587249048f71 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Mon, 17 Sep 2018 17:34:13 +0200 Subject: Dive media: on import read metadata only once On import of dive media, the timestamp is read from the metadata to check if the image belongs to the selected dives. The pictures are then listed in a dialog. Currently, the metadata is read twice if images are outside of a dive: once in picture_check_valid() and if it turns out that the picture is not valid again in picture_get_time() to display the proper timestamp. Even though metadata-extraction is reasonably fast, this is a bit of an embarrassment. Instead, read the timestamps only once in the constructor of the dialog and from then on only used these timestamps. Keep the timestamps in a QVector. Rename the picture_check_valid() function to picture_check_valid_time() and pass a timestamp instead of a filename. Signed-off-by: Berthold Stoeger --- core/dive.c | 3 +-- core/dive.h | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'core') diff --git a/core/dive.c b/core/dive.c index 67cfc5fa5..0c185efa5 100644 --- a/core/dive.c +++ b/core/dive.c @@ -3871,12 +3871,11 @@ bool dive_check_picture_time(const struct dive *d, int shift_time, timestamp_t t return false; } -bool picture_check_valid(const char *filename, int shift_time) +bool picture_check_valid_time(timestamp_t timestamp, int shift_time) { int i; struct dive *dive; - timestamp_t timestamp = picture_get_timestamp(filename); for_each_dive (i, dive) if (dive->selected && dive_check_picture_time(dive, shift_time, timestamp)) return true; diff --git a/core/dive.h b/core/dive.h index 277050f5e..3344aaf35 100644 --- a/core/dive.h +++ b/core/dive.h @@ -382,7 +382,7 @@ extern void dive_create_picture(struct dive *d, const char *filename, int shift_ extern void dive_add_picture(struct dive *d, struct picture *newpic); extern bool dive_remove_picture(struct dive *d, const char *filename); extern unsigned int dive_get_picture_count(struct dive *d); -extern bool picture_check_valid(const char *filename, int shift_time); +extern bool picture_check_valid_time(timestamp_t timestamp, int shift_time); extern void dive_set_geodata_from_picture(struct dive *d, struct picture *pic); extern void picture_free(struct picture *picture); -- cgit v1.2.3-70-g09d2