From 8be9ebae77e559de0513623090a7461701a2eee2 Mon Sep 17 00:00:00 2001 From: Guilherme Affonso Date: Thu, 5 May 2022 16:48:52 +0900 Subject: [PATCH] Count deleted members in package intsymcount and symcount --- lisp/c/intern.c | 25 ++++++++++++++++--------- lisp/l/packsym.l | 10 +++++----- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/lisp/c/intern.c b/lisp/c/intern.c index b8f6d1901..f3b683d97 100644 --- a/lisp/c/intern.c +++ b/lisp/c/intern.c @@ -45,8 +45,9 @@ register pointer symvec; if (++hash>=size) hash=0;} while (1);} -static pointer extendsymvec(symvec) +static pointer extendsymvec(symvec, count) pointer symvec; +int* count; { register pointer newsymvec,sym; bpointer bp; register int i,newsize,size,hash; @@ -58,10 +59,12 @@ pointer symvec; newsize=buddysize[bp->h.bix+1]-2; #endif newsymvec=makevector(C_VECTOR,newsize); + *count=0; for (i=0; ic.vec.v[i]=makeint(0); /*empty mark*/ for (i=0; ic.vec.v[i]; if (issymbol(sym)) { + ++(*count); hash=rehash(sym->c.sym.pname) % newsize; while (newsymvec->c.vec.v[hash]!=makeint(0)) { /*find an empty slot*/ if (++hash>=newsize) hash=0;} @@ -74,8 +77,8 @@ pointer symvec; pointer export(sym,pkg) pointer sym,pkg; { register pointer symvec=pkg->c.pkg.symvector; /*external symbol table*/ - register int size, newsymcount; - int hash; + register int size; + int hash, newsymcount; pointer usedby,usedbylist=pkg->c.pkg.used_by; pointer pnam,s; @@ -93,11 +96,13 @@ pointer sym,pkg; while (1) { if (symvec->c.vec.v[hash]==sym) return(sym); if (isint(symvec->c.vec.v[hash])) { + newsymcount=intval(pkg->c.pkg.symcount); + if(intval(symvec->c.vec.v[hash]) == 0) // only increase count if empty + newsymcount+=1; pointer_update(symvec->c.vec.v[hash],sym); - newsymcount=intval(pkg->c.pkg.symcount)+1; + if (newsymcount > (size / 2)) + pointer_update(pkg->c.pkg.symvector, extendsymvec(symvec, &newsymcount)); pkg->c.pkg.symcount=makeint(newsymcount); - if (newsymcount > (size / 2)) - pointer_update(pkg->c.pkg.symvector, extendsymvec(symvec)); return(sym);} else if (++hash>=size) hash=0;} } @@ -123,17 +128,19 @@ pointer pkg; /*destination package*/ newsym=makesymbol(ctx,id,l,pkg); /*put it in the package*/ while (issymbol(symvec->c.vec.v[hash])) if (++hash>=size) hash=0; + l=intval(pkg->c.pkg.intsymcount); + if (intval(symvec->c.vec.v[hash]) == 0) // only increase count if empty + l+=1; pointer_update(symvec->c.vec.v[hash],newsym); if (pkg==keywordpkg) { newsym->c.sym.vtype=V_CONSTANT; pointer_update(newsym->c.sym.speval,newsym); export(newsym,pkg);} - l=intval(pkg->c.pkg.intsymcount)+1; - pkg->c.pkg.intsymcount=makeint(l); if (l>(size/2)) { /*extend hash table*/ vpush(newsym); - pointer_update(pkg->c.pkg.intsymvector,extendsymvec(symvec)); + pointer_update(pkg->c.pkg.intsymvector,extendsymvec(symvec, &l)); vpop();} + pkg->c.pkg.intsymcount=makeint(l); /* export all the symbols to avoid incompatibility with old EusLisp*/ if (export_all) export(newsym, pkg); #ifdef SAFETY diff --git a/lisp/l/packsym.l b/lisp/l/packsym.l index 7ed3cc73c..3fb3c388c 100644 --- a/lisp/l/packsym.l +++ b/lisp/l/packsym.l @@ -150,8 +150,10 @@ (if (>= intsymcount size) (error "can not enter ~a into this package, maximum symbol size is ~a" sym size)) (while (symbolp (svref intsymvector hash)) (if (>= (setq hash (1+ hash)) size) (setq hash 0))) + (if (= (elt intsymvector hash) 0) + (setq intsymcount (1+ intsymcount))) (svset intsymvector hash sym) - (setq intsymcount (1+ intsymcount)) + ;; TODO: expand if necessary sym)) (:find (s) ;find symbol just in this package (declare (symbol s)) @@ -179,12 +181,10 @@ (setq (sym . homepkg) nil)) (setq pos (send self :find sym)) (when pos - (svset intsymvector pos 1) ;deleted mark - (setq intsymcount (1- intsymcount))) + (svset intsymvector pos 1)) ;deleted mark (setq pos (send self :find-external sym)) (when pos - (svset symvector pos 1) ;deleted mark - (setq symcount (1- symcount))) + (svset symvector pos 1)) ;deleted mark )) (:find-external (s) (declare (symbol s))