aboutsummaryrefslogtreecommitdiffstats
path: root/libdivecomputer.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2012-11-23 16:05:38 -1000
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-11-23 19:33:39 -0800
commita9786564c23fbf032f47096f543699c8c402785b (patch)
tree551231e54e017c9e83fd44da59edbe4c94dfa716 /libdivecomputer.c
parent10ce60e2120419282ff7694e8deda60e94832aa1 (diff)
downloadsubsurface-a9786564c23fbf032f47096f543699c8c402785b.tar.gz
Allocate dive samples separately from 'struct dive'
We used to avoid some extra allocations by just allocating the dive samples as part of the 'struct dive' allocation itself, but that ends up complicating things, and will make it impossible to have multiple different sets of samples (for multiple dive computers). So stop doing it. Just allocate the dive samples array separately. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'libdivecomputer.c')
-rw-r--r--libdivecomputer.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/libdivecomputer.c b/libdivecomputer.c
index d4ffcc174..6ced23a48 100644
--- a/libdivecomputer.c
+++ b/libdivecomputer.c
@@ -115,8 +115,7 @@ void
sample_cb(dc_sample_type_t type, dc_sample_value_t value, void *userdata)
{
int i;
- struct dive **divep = userdata;
- struct dive *dive = *divep;
+ struct dive *dive = userdata;
struct sample *sample;
/*
@@ -127,9 +126,9 @@ sample_cb(dc_sample_type_t type, dc_sample_value_t value, void *userdata)
switch (type) {
case DC_SAMPLE_TIME:
- sample = prepare_sample(divep);
+ sample = prepare_sample(dive);
sample->time.seconds = value.time;
- finish_sample(*divep);
+ finish_sample(dive);
break;
case DC_SAMPLE_DEPTH:
sample->depth.mm = value.depth * 1000 + 0.5;
@@ -177,10 +176,10 @@ static void dev_info(device_data_t *devdata, const char *fmt, ...)
static int import_dive_number = 0;
-static int parse_samples(device_data_t *devdata, struct dive **divep, dc_parser_t *parser)
+static int parse_samples(device_data_t *devdata, struct dive *dive, dc_parser_t *parser)
{
// Parse the sample data.
- return dc_parser_samples_foreach(parser, sample_cb, divep);
+ return dc_parser_samples_foreach(parser, sample_cb, dive);
}
/*
@@ -303,7 +302,7 @@ static int dive_cb(const unsigned char *data, unsigned int size,
}
// Initialize the sample data.
- rc = parse_samples(devdata, &dive, parser);
+ rc = parse_samples(devdata, dive, parser);
if (rc != DC_STATUS_SUCCESS) {
dev_info(devdata, _("Error parsing the samples"));
dc_parser_destroy(parser);