From 36e45dfccb5e5321682c0ec24dead22cf40fcb16 Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Wed, 9 Feb 2022 17:06:41 +0000 Subject: Make the array type a tiny bit smaller, by packing control information into a bit array --- print.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'print.c') diff --git a/print.c b/print.c index 232fc54..075d372 100644 --- a/print.c +++ b/print.c @@ -48,28 +48,28 @@ ppdatums(Datum **ds, int n) Rune * pparray(Array *a) { - Rune **elemstrs = emalloc(sizeof(Rune *) * a->size); + Rune **elemstrs = emalloc(sizeof(Rune *) * GetSize(a)); int rowcount = 1; - if(a->rank > 0){ - for(int i = 0; i < a->rank-1; i++) + if(GetRank(a) > 0){ + for(int i = 0; i < GetRank(a)-1; i++) rowcount *= a->shape[i]; } Rune **rowstrs = emallocz(sizeof(Rune *) * rowcount, 1); int boxing = !simplearray(a); - char *align = a->type == AtypeArray ? "-" : ""; - for(int i = 0; i < a->size; i++){ - if(a->type == AtypeArray){ + char *align = GetType(a) == AtypeArray ? "-" : ""; + for(int i = 0; i < GetSize(a); i++){ + if(GetType(a) == AtypeArray){ Rune *arrstr = pparray(a->arraydata[i]); elemstrs[i] = runesmprint("%S", arrstr); free(arrstr); }else{ Array *e = arrayitem(a, i); /* a scalar */ - if(e->type == AtypeInt) + if(GetType(e) == AtypeInt) elemstrs[i] = runesmprint("%lld", e->intdata[0]); - else if(e->type == AtypeRune) + else if(GetType(e) == AtypeRune) elemstrs[i] = runesmprint("%C", e->runedata[0]); - else if(e->type == AtypeFloat){ + else if(GetType(e) == AtypeFloat){ char *fmt = smprint("%%.%df", printprecision); elemstrs[i] = runesmprint(fmt, e->floatdata[0]); free(fmt); @@ -82,17 +82,17 @@ pparray(Array *a) } } - if(elemstrs[i][0] == '-' && (e->type == AtypeInt || e->type == AtypeFloat)) + if(elemstrs[i][0] == '-' && (GetType(e) == AtypeInt || GetType(e) == AtypeFloat)) elemstrs[i][0] = L'¯'; freearray(e); } } - int lastdim = a->rank ? a->shape[a->rank-1] : 1; + int lastdim = GetRank(a) ? a->shape[GetRank(a)-1] : 1; int *widths = emallocz(sizeof(int) * lastdim, 1); int *heights = emallocz(sizeof(int) * rowcount, 1); - for(int i = 0; i < a->size; i++){ + for(int i = 0; i < GetSize(a); i++){ int w,h; strdims(elemstrs[i], &w, &h); if(w > widths[i%lastdim]) @@ -119,7 +119,7 @@ pparray(Array *a) Rune *spacing; if(boxing) spacing = L"│"; - else if(x == lastdim - 1 || a->type == AtypeRune) + else if(x == lastdim - 1 || GetType(a) == AtypeRune) spacing = L""; else spacing = L" "; @@ -148,8 +148,8 @@ pparray(Array *a) res = printborder(res, widths, lastdim, 0); int j = 1; int blanks = 0; - for(int dim = 0; dim < a->rank - 1 && i+1 != a->size; dim++){ - j *= a->shape[a->rank-dim-2]; + for(int dim = 0; dim < GetRank(a) - 1 && i+1 != GetSize(a); dim++){ + j *= a->shape[GetRank(a)-dim-2]; if(i%j == 0) blanks++; } -- cgit v1.2.3