From: Ben Pfaff Date: Sun, 7 May 2006 05:44:18 +0000 (+0000) Subject: Improvements to case implementation. X-Git-Tag: v0.6.0~880 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1e84687727b7fdad133fd7d2b9b20737fb13e167;p=pspp-builds.git Improvements to case implementation. --- diff --git a/src/data/ChangeLog b/src/data/ChangeLog index 6277dbe5..c3b44971 100644 --- a/src/data/ChangeLog +++ b/src/data/ChangeLog @@ -1,3 +1,10 @@ +Sat May 6 22:42:23 2006 Ben Pfaff + + * case.c (case_move): Do nothing if dst and src are the same + object. + (case_try_create) Merge two similar cases. + (case_copy) Unshare only if data must be actually copied. + Sun May 7 10:04:06 WST 2006 John Darrington * data-in.c data-out.c dictionary.c sys-file-reader.c diff --git a/src/data/case.c b/src/data/case.c index eab966b1..6e65af97 100644 --- a/src/data/case.c +++ b/src/data/case.c @@ -126,10 +126,13 @@ case_move (struct ccase *dst, struct ccase *src) assert (src->case_data != NULL); assert (src->case_data->ref_cnt > 0); assert (dst != NULL); - - *dst = *src; - dst->this = dst; - case_nullify (src); + + if (dst != src) + { + *dst = *src; + dst->this = dst; + case_nullify (src); + } } #endif /* DEBUGGING */ @@ -180,23 +183,18 @@ case_swap (struct ccase *a, struct ccase *b) int case_try_create (struct ccase *c, size_t value_cnt) { +#ifdef DEBUGGING + c->this = c; +#endif c->case_data = malloc (case_size (value_cnt)); if (c->case_data != NULL) { -#ifdef DEBUGGING - c->this = c; -#endif c->case_data->value_cnt = value_cnt; c->case_data->ref_cnt = 1; return 1; } else - { -#ifdef DEBUGGING - c->this = c; -#endif - return 0; - } + return 0; } /* Tries to initialize CLONE as a copy of ORIG. @@ -229,12 +227,14 @@ case_copy (struct ccase *dst, size_t dst_idx, assert (src->case_data->ref_cnt > 0); assert (src_idx + value_cnt <= dst->case_data->value_cnt); - if (dst->case_data->ref_cnt > 1) - case_unshare (dst); if (dst->case_data != src->case_data || dst_idx != src_idx) - memmove (dst->case_data->values + dst_idx, - src->case_data->values + src_idx, - sizeof *dst->case_data->values * value_cnt); + { + if (dst->case_data->ref_cnt > 1) + case_unshare (dst); + memmove (dst->case_data->values + dst_idx, + src->case_data->values + src_idx, + sizeof *dst->case_data->values * value_cnt); + } } #endif /* DEBUGGING */ diff --git a/src/data/case.h b/src/data/case.h index bdb68dc6..05c4568c 100644 --- a/src/data/case.h +++ b/src/data/case.h @@ -115,8 +115,11 @@ case_clone (struct ccase *clone, const struct ccase *orig) static inline void case_move (struct ccase *dst, struct ccase *src) { - *dst = *src; - src->case_data = NULL; + if (dst != src) + { + *dst = *src; + src->case_data = NULL; + } } static inline void @@ -132,12 +135,14 @@ case_copy (struct ccase *dst, size_t dst_idx, const struct ccase *src, size_t src_idx, size_t value_cnt) { - if (dst->case_data->ref_cnt > 1) - case_unshare (dst); if (dst->case_data != src->case_data || dst_idx != src_idx) - memmove (dst->case_data->values + dst_idx, - src->case_data->values + src_idx, - sizeof *dst->case_data->values * value_cnt); + { + if (dst->case_data->ref_cnt > 1) + case_unshare (dst); + memmove (dst->case_data->values + dst_idx, + src->case_data->values + src_idx, + sizeof *dst->case_data->values * value_cnt); + } } static inline void