mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
10ce60e212
commit
a9786564c2
7 changed files with 45 additions and 66 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue