+Sat May 6 22:42:23 2006 Ben Pfaff <blp@gnu.org>
+
+ * 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 <john@darrington.wattle.id.au>
* data-in.c data-out.c dictionary.c sys-file-reader.c
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 */
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.
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 */
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
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