From: Ben Pfaff Date: Mon, 4 Jun 2007 01:43:27 +0000 (+0000) Subject: Slightly generalize case_to_values and case_from_values functions, and X-Git-Tag: v0.6.0~453 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=522f263565607b97b83d26bff49b5fa44704df33;p=pspp-builds.git Slightly generalize case_to_values and case_from_values functions, and update callers. --- diff --git a/src/data/ChangeLog b/src/data/ChangeLog index cb1085b3..8fd50a07 100644 --- a/src/data/ChangeLog +++ b/src/data/ChangeLog @@ -1,3 +1,13 @@ +2007-06-03 Ben Pfaff + + Slightly generalize case_to_values and case_from_values functions. + + * case.c (case_to_values): Rename case_copy_out, change interface. + (case_from_values): Rename case_copy_in, change interface. + + * fastfile.c (fastfilereader_get_next_case): Update caller. + (write_case_to_disk): Ditto. + 2007-06-02 Ben Pfaff Clean up after a forgotten part of patch #5829. diff --git a/src/data/case.c b/src/data/case.c index b09a10f2..cd559c0f 100644 --- a/src/data/case.c +++ b/src/data/case.c @@ -210,35 +210,33 @@ case_copy (struct ccase *dst, size_t dst_idx, } } -/* Copies case C to OUTPUT. - OUTPUT_SIZE is the number of `union values' in OUTPUT, - which must match the number of `union values' in C. */ +/* Copies VALUE_CNT values out of case C to VALUES, starting at + the given START_IDX. */ void -case_to_values (const struct ccase *c, union value *output, - size_t output_size UNUSED) +case_copy_out (const struct ccase *c, + size_t start_idx, union value *values, size_t value_cnt) { assert (c->case_data->ref_cnt > 0); - assert (output_size == c->case_data->value_cnt); - assert (output != NULL || output_size == 0); + assert (value_cnt <= c->case_data->value_cnt); + assert (start_idx + value_cnt <= c->case_data->value_cnt); - memcpy (output, c->case_data->values, - c->case_data->value_cnt * sizeof *output); + memcpy (values, c->case_data->values + start_idx, + value_cnt * sizeof *values); } -/* Copies INPUT into case C. - INPUT_SIZE is the number of `union values' in INPUT, - which must match the number of `union values' in C. */ +/* Copies VALUE_CNT values from VALUES into case C, staring at + the given START_IDX. */ void -case_from_values (struct ccase *c, const union value *input, - size_t input_size UNUSED) +case_copy_in (struct ccase *c, + size_t start_idx, const union value *values, size_t value_cnt) { assert (c->case_data->ref_cnt > 0); - assert (input_size == c->case_data->value_cnt); - assert (input != NULL || input_size == 0); + assert (value_cnt <= c->case_data->value_cnt); + assert (start_idx + value_cnt <= c->case_data->value_cnt); case_unshare (c); - memcpy (c->case_data->values, input, - c->case_data->value_cnt * sizeof *input); + memcpy (c->case_data->values + start_idx, values, + value_cnt * sizeof *values); } /* Returns a pointer to the `union value' used for the diff --git a/src/data/case.h b/src/data/case.h index 587ab28a..4d6e1d47 100644 --- a/src/data/case.h +++ b/src/data/case.h @@ -51,12 +51,13 @@ bool case_try_create (struct ccase *, size_t value_cnt); bool case_try_clone (struct ccase *, const struct ccase *); void case_copy (struct ccase *dst, size_t dst_idx, - const struct ccase *src, size_t src_idx, - size_t cnt); + const struct ccase *src, size_t src_idx, + size_t cnt); -void case_to_values (const struct ccase *, union value *, size_t); -void case_from_values (struct ccase *, - const union value *, size_t); +void case_copy_out (const struct ccase *, + size_t start_idx, union value *, size_t value_cnt); +void case_copy_in (struct ccase *, + size_t start_idx, const union value *, size_t value_cnt); const union value *case_data (const struct ccase *, const struct variable *); double case_num (const struct ccase *, const struct variable *); diff --git a/src/data/fastfile.c b/src/data/fastfile.c index 7fa6eb85..5856d07c 100644 --- a/src/data/fastfile.c +++ b/src/data/fastfile.c @@ -246,8 +246,7 @@ fastfilereader_get_next_case (struct casereader *cr) ffr->buffer_pos = 0; } - case_from_values (&ffr->c, ffr->buffer + ffr->buffer_pos, - ff->value_cnt); + case_copy_in (&ffr->c, 0, ffr->buffer + ffr->buffer_pos, ff->value_cnt); ffr->buffer_pos += ff->value_cnt; read_case = &ffr->c; @@ -645,7 +644,7 @@ write_case_to_disk (struct fastfile *ff, const struct ccase *c) if (!ff->ok) return; - case_to_values (c, ff->buffer + ff->buffer_used, ff->value_cnt); + case_copy_out (c, 0, ff->buffer + ff->buffer_used, ff->value_cnt); ff->buffer_used += ff->value_cnt; if (ff->buffer_used + ff->value_cnt > ff->buffer_size) flush_buffer (ff);