summaryrefslogtreecommitdiffstats
path: root/subsurface-core/dive.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2016-04-03 17:31:59 -0500
committerGravatar Dirk Hohndel <dirk@hohndel.org>2016-04-04 17:27:10 -0700
commit2d760a7bff71c46c5aeba37c40d236ea16eefea2 (patch)
tree31520cecba5722150f8cddfcf627351ea1257f4f /subsurface-core/dive.c
parent2b36091599cbc51474e103f14037e5ac44215cf3 (diff)
downloadsubsurface-2d760a7bff71c46c5aeba37c40d236ea16eefea2.tar.gz
Don't write back dive data that hasn't changed in git
This caches the git ID for the dive on load, and avoids building the dive directory and hashing it on save as long as nothing has invalidated the git ID cache. That should make it much faster to write back data to the git repository, since the dive tree structure and the divecomputer blobs in particular are the bulk of it (due to all the sample data). It's not actually the git operations that are all that expensive, it's literally generating the big blob with all the snprintf() calls for the data. The git save used to be a fairly expensive with large data sets, especially noticeable on mobile with much weaker CPU's. This should speed things up by at least a factor of two. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'subsurface-core/dive.c')
-rw-r--r--subsurface-core/dive.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/subsurface-core/dive.c b/subsurface-core/dive.c
index 12154704f..ce730da28 100644
--- a/subsurface-core/dive.c
+++ b/subsurface-core/dive.c
@@ -156,6 +156,7 @@ void update_event_name(struct dive *d, struct event *event, char *name)
*removep = (*removep)->next;
add_event(dc, event->time.seconds, event->type, event->flags, event->value, name);
free(remove);
+ invalidate_dive_cache(d);
}
void add_extra_data(struct divecomputer *dc, const char *key, const char *value)
@@ -464,6 +465,7 @@ void copy_dive(struct dive *s, struct dive *d)
* relevant components that are referenced through pointers,
* so all the strings and the structured lists */
*d = *s;
+ invalidate_dive_cache(d);
d->buddy = copy_string(s->buddy);
d->divemaster = copy_string(s->divemaster);
d->notes = copy_string(s->notes);
@@ -474,11 +476,10 @@ void copy_dive(struct dive *s, struct dive *d)
d->weightsystem[i].description = copy_string(s->weightsystem[i].description);
STRUCTURED_LIST_COPY(struct picture, s->picture_list, d->picture_list, copy_pl);
STRUCTURED_LIST_COPY(struct tag_entry, s->tag_list, d->tag_list, copy_tl);
+
+ // Copy the first dc explicitly, then the list of subsequent dc's
+ copy_dc(&s->dc, &d->dc);
STRUCTURED_LIST_COPY(struct divecomputer, s->dc.next, d->dc.next, copy_dc);
- /* this only copied dive computers 2 and up. The first dive computer is part
- * of the struct dive, so let's make copies of its samples and events */
- copy_samples(&s->dc, &d->dc);
- copy_events(&s->dc, &d->dc);
}
/* make a clone of the source dive and clean out the source dive;
@@ -3247,6 +3248,7 @@ void shift_times(const timestamp_t amount)
if (!dive->selected)
continue;
dive->when += amount;
+ invalidate_dive_cache(dive);
}
}
@@ -3410,6 +3412,7 @@ void dive_create_picture(struct dive *dive, char *filename, int shift_time, bool
dive_add_picture(dive, picture);
dive_set_geodata_from_picture(dive, picture);
+ invalidate_dive_cache(dive);
}
void dive_add_picture(struct dive *dive, struct picture *newpic)
@@ -3441,6 +3444,7 @@ void dive_set_geodata_from_picture(struct dive *dive, struct picture *picture)
ds->longitude = picture->longitude;
} else {
dive->dive_site_uuid = create_dive_site_with_gps("", picture->latitude, picture->longitude, dive->when);
+ invalidate_dive_cache(dive);
}
}
}
@@ -3475,6 +3479,7 @@ void dive_remove_picture(char *filename)
struct picture *temp = (*picture)->next;
picture_free(*picture);
*picture = temp;
+ invalidate_dive_cache(current_dive);
}
}
@@ -3498,6 +3503,7 @@ void make_first_dc()
current_dive->dc = *cur_dc;
current_dive->dc.next = newdc;
free(cur_dc);
+ invalidate_dive_cache(current_dive);
}
/* always acts on the current dive */
@@ -3537,6 +3543,7 @@ void delete_current_divecomputer(void)
}
if (dc_number == count_divecomputers())
dc_number--;
+ invalidate_dive_cache(current_dive);
}
/* helper function to make it easier to work with our structures