From a8874ced3f222cc5f4ed963a09c3491ac36610a6 Mon Sep 17 00:00:00 2001 From: lemon Date: Sun, 9 Oct 2022 13:06:25 +0200 Subject: upval size optimization --- pez.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'pez.c') diff --git a/pez.c b/pez.c index 40d097b..d965095 100644 --- a/pez.c +++ b/pez.c @@ -86,9 +86,11 @@ typedef struct Proto { typedef struct Upval Upval; struct Upval { OBJHEADER; - Upval *nextup; Val *ptr; - Val slot; + union { + Upval *nextup; + Val slot; + }; }; typedef struct Fn { @@ -471,11 +473,12 @@ delproto(PezContext *cx, Proto *pr) static void closeups(PezContext *cx, Val *vals) { - for (Upval *up = cx->openup; up; up = up->nextup) { + for (Upval *up = cx->openup, *next; up; up = next) { + next = up->nextup; if (up->ptr >= vals) { + cx->openup = next; up->slot = *up->ptr; up->ptr = &up->slot; - cx->openup = up->nextup; } } } -- cgit v1.2.3