Mercurial > libjeffpc
changeset 350:cc22716beb4a
val: preallocate () VT_CONS
Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author | Josef 'Jeff' Sipek <jeffpc@josefsipek.net> |
---|---|
date | Thu, 10 Aug 2017 22:23:07 +0300 |
parents | 21f04e72ca8a |
children | 10ed10c37739 |
files | val.c |
diffstat | 1 files changed, 12 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/val.c Fri Aug 11 14:07:31 2017 +0300 +++ b/val.c Thu Aug 10 22:23:07 2017 +0300 @@ -42,6 +42,7 @@ .memb = (val), \ } +static const struct val val_cons_empty = INIT_STATIC_VAL(VT_CONS, i, 0); static const struct val val_true = INIT_STATIC_VAL(VT_BOOL, b, true); static const struct val val_false = INIT_STATIC_VAL(VT_BOOL, b, false); static const struct val val_null = INIT_STATIC_VAL(VT_NULL, i, 0); @@ -175,6 +176,17 @@ { struct val *val; + if (!head && !tail) { + /* + * Cast away the const - we define the static as const to + * get it into .rodata, but we have to drop the const since + * everything expects struct val to be writable (because + * refcounts modify it). In this case, we won't get any + * modifications because we're marked as static. + */ + return (struct val *) &val_cons_empty; + } + val = __val_alloc(VT_CONS); if (IS_ERR(val)) { val_putref(head);