From 2365531c686be62954c201a690d89e0eebdef456 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Wed, 10 Jun 2015 07:13:00 -0700 Subject: [PATCH] When saving only selected dives, only include referenced dive sites The algorithm seems rather brute force; basically quadratic in the number of dives, assuming we have about the same number of dive sites as dives which seems a reasonable assumotion. Signed-off-by: Dirk Hohndel --- save-xml.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/save-xml.c b/save-xml.c index 173f6a8ec..58f274722 100644 --- a/save-xml.c +++ b/save-xml.c @@ -509,10 +509,10 @@ void save_dives_buffer(struct membuffer *b, const bool select_only) /* save the dive sites */ put_format(b, "\n"); for (i = 0; i < dive_site_table.nr; i++) { + int j; + struct dive *d; struct dive_site *ds = get_dive_site(i); if (dive_site_is_empty(ds)) { - int j; - struct dive *d; for_each_dive(j, d) { if (d->dive_site_uuid == ds->uuid) d->dive_site_uuid = 0; @@ -521,6 +521,17 @@ void save_dives_buffer(struct membuffer *b, const bool select_only) i--; // since we just deleted that one continue; } + if (select_only) { + bool found = false; + for_each_dive(j, d) { + if (d->selected && d->dive_site_uuid == ds->uuid) { + found = true; + break; + } + } + if (!found) + continue; + } put_format(b, "uuid); show_utf8(b, ds->name, " name='", "'", 1); if (ds->latitude.udeg || ds->longitude.udeg) {