projects
/
pspp-builds.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
value: New function value_swap.
[pspp-builds.git]
/
src
/
data
/
value.h
diff --git
a/src/data/value.h
b/src/data/value.h
index 8f1746337ea37ceaefa3523fa73ff0c2666b63f8..046a9a3aa638a5e69b77bbecca8f8447e30d820b 100644
(file)
--- a/
src/data/value.h
+++ b/
src/data/value.h
@@
-23,8
+23,12
@@
#include <string.h>
#include "xalloc.h"
\f
#include <string.h>
#include "xalloc.h"
\f
+/* Maximum length of a "short" string, that is represented in
+ "union value" without a separate pointer.
+
+ This is an implementation detail of the "union value" code.
+ There is little reason for client code to use it. */
#define MAX_SHORT_STRING 8
#define MAX_SHORT_STRING 8
-#define MIN_LONG_STRING (MAX_SHORT_STRING + 1)
/* A numeric or string value.
/* A numeric or string value.
@@
-74,6
+78,8
@@
bool value_is_resizable (const union value *, int old_width, int new_width);
bool value_needs_resize (int old_width, int new_width);
void value_resize (union value *, int old_width, int new_width);
bool value_needs_resize (int old_width, int new_width);
void value_resize (union value *, int old_width, int new_width);
+static inline void value_swap (union value *, union value *);
+
struct pool;
void value_init_pool (struct pool *, union value *, int width);
void value_resize_pool (struct pool *, union value *,
struct pool;
void value_init_pool (struct pool *, union value *, int width);
void value_resize_pool (struct pool *, union value *,
@@
-148,7
+154,7
@@
static inline const char *
value_str (const union value *v, int width)
{
assert (width > 0);
value_str (const union value *v, int width)
{
assert (width > 0);
- return (width >
= MIN_LONG
_STRING ? v->long_string : v->short_string);
+ return (width >
MAX_SHORT
_STRING ? v->long_string : v->short_string);
}
/* Returns the string value in V, which must have width WIDTH.
}
/* Returns the string value in V, which must have width WIDTH.
@@
-162,7
+168,7
@@
static inline char *
value_str_rw (union value *v, int width)
{
assert (width > 0);
value_str_rw (union value *v, int width)
{
assert (width > 0);
- return (width >
= MIN_LONG
_STRING ? v->long_string : v->short_string);
+ return (width >
MAX_SHORT
_STRING ? v->long_string : v->short_string);
}
/* Copies SRC to DST, given that they both contain data of the
}
/* Copies SRC to DST, given that they both contain data of the
@@
-176,4
+182,13
@@
value_copy (union value *dst, const union value *src, int width)
memcpy (dst->long_string, src->long_string, width);
}
memcpy (dst->long_string, src->long_string, width);
}
+/* Exchanges the contents of A and B. */
+static inline void
+value_swap (union value *a, union value *b)
+{
+ union value tmp = *a;
+ *a = *b;
+ *b = tmp;
+}
+
#endif /* data/value.h */
#endif /* data/value.h */