summaryrefslogtreecommitdiffstats
path: root/subsurface-core/dive.h
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.h
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.h')
-rw-r--r--subsurface-core/dive.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/subsurface-core/dive.h b/subsurface-core/dive.h
index 204d34819..ae24b7409 100644
--- a/subsurface-core/dive.h
+++ b/subsurface-core/dive.h
@@ -339,8 +339,20 @@ struct dive {
int id; // unique ID for this dive
struct picture *picture_list;
int oxygen_cylinder_index, diluent_cylinder_index; // CCR dive cylinder indices
+ unsigned char git_id[20];
};
+static inline void invalidate_dive_cache(struct dive *dive)
+{
+ memset(dive->git_id, 0, 20);
+}
+
+static inline bool dive_cache_is_valid(const struct dive *dive)
+{
+ static const unsigned char null_id[20] = { 0, };
+ return !!memcmp(dive->git_id, null_id, 20);
+}
+
extern int get_cylinder_idx_by_use(struct dive *dive, enum cylinderuse cylinder_use_type);
extern void dc_cylinder_renumber(struct dive *dive, struct divecomputer *dc, int mapping[]);
@@ -755,6 +767,7 @@ extern int nr_weightsystems(struct dive *dive);
extern void add_cylinder_description(cylinder_type_t *);
extern void add_weightsystem_description(weightsystem_t *);
extern void remember_event(const char *eventname);
+extern void invalidate_dive_cache(struct dive *dc);
#if WE_DONT_USE_THIS /* this is a missing feature in Qt - selecting which events to display */
extern int evn_foreach(void (*callback)(const char *, bool *, void *), void *data);