diff options
| author | Keith Packard <keithp@keithp.com> | 2016-11-14 21:25:38 -0800 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2017-02-20 11:16:50 -0800 | 
| commit | 5557f6b87a9b8bc9716de8191f2062a772a6ae6c (patch) | |
| tree | 65f437f42e7ab4b49587c7f70f4105b99409e45c /src/lisp/ao_lisp_cons.c | |
| parent | ce549b2c11e6b2571590021e1c0503d8a6e7a702 (diff) | |
altos/lisp: Cache freed cons and stack items
Track freed cons cells and stack items from the eval process where
possible so that they can be re-used without needing to collect.
This dramatically reduces the number of collect calls.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/lisp/ao_lisp_cons.c')
| -rw-r--r-- | src/lisp/ao_lisp_cons.c | 32 | 
1 files changed, 25 insertions, 7 deletions
diff --git a/src/lisp/ao_lisp_cons.c b/src/lisp/ao_lisp_cons.c index 311d63ab..d2b60c9a 100644 --- a/src/lisp/ao_lisp_cons.c +++ b/src/lisp/ao_lisp_cons.c @@ -69,24 +69,42 @@ const struct ao_lisp_type ao_lisp_cons_type = {  	.name = "cons",  }; +struct ao_lisp_cons *ao_lisp_cons_free_list; +  struct ao_lisp_cons *  ao_lisp_cons_cons(ao_poly car, struct ao_lisp_cons *cdr)  {  	struct ao_lisp_cons	*cons; -	ao_lisp_poly_stash(0, car); -	ao_lisp_cons_stash(0, cdr); -	cons = ao_lisp_alloc(sizeof (struct ao_lisp_cons)); -	car = ao_lisp_poly_fetch(0); -	cdr = ao_lisp_cons_fetch(0); -	if (!cons) -		return NULL; +	if (ao_lisp_cons_free_list) { +		cons = ao_lisp_cons_free_list; +		ao_lisp_cons_free_list = ao_lisp_poly_cons(cons->cdr); +	} else { +		ao_lisp_poly_stash(0, car); +		ao_lisp_cons_stash(0, cdr); +		cons = ao_lisp_alloc(sizeof (struct ao_lisp_cons)); +		car = ao_lisp_poly_fetch(0); +		cdr = ao_lisp_cons_fetch(0); +		if (!cons) +			return NULL; +	}  	cons->car = car;  	cons->cdr = ao_lisp_cons_poly(cdr);  	return cons;  }  void +ao_lisp_cons_free(struct ao_lisp_cons *cons) +{ +	while (cons) { +		ao_poly cdr = cons->cdr; +		cons->cdr = ao_lisp_cons_poly(ao_lisp_cons_free_list); +		ao_lisp_cons_free_list = cons; +		cons = ao_lisp_poly_cons(cdr); +	} +} + +void  ao_lisp_cons_print(ao_poly c)  {  	struct ao_lisp_cons *cons = ao_lisp_poly_cons(c);  | 
