From d722e4a6b24eb4242e92d24c98c6eec67f356037 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 19 Aug 2024 17:35:28 +0200 Subject: [PATCH] kernel: add NEW_BLIST --- src/blister.c | 10 +++------- src/blister.h | 15 +++++++++++++++ src/listfunc.c | 3 +-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/blister.c b/src/blister.c index b0ea7e49fe..7076ce5da2 100644 --- a/src/blister.c +++ b/src/blister.c @@ -431,8 +431,7 @@ static Obj ElmsBlist(Obj list, Obj poss) lenPoss = LEN_LIST( poss ); // make the result list - elms = NewBag( T_BLIST, SIZE_PLEN_BLIST( lenPoss ) ); - SET_LEN_BLIST( elms, lenPoss ); + elms = NEW_BLIST( lenPoss ); // loop over the entries of and select block = 0; bit = 1; @@ -492,8 +491,7 @@ static Obj ElmsBlist(Obj list, Obj poss) } // make the result list - elms = NewBag( T_BLIST, SIZE_PLEN_BLIST( lenPoss ) ); - SET_LEN_BLIST( elms, lenPoss ); + elms = NEW_BLIST(lenPoss); if (inc == 1) { CopyBits(CONST_BLOCKS_BLIST(list) + ((pos - 1) / BIPEB), @@ -1099,9 +1097,7 @@ static Obj FuncBLIST_LIST(Obj self, Obj list, Obj sub) RequireSmallList(SELF_NAME, list); RequireSmallList(SELF_NAME, sub); - Int lenList = LEN_LIST( list ); - Obj blist = NewBag( T_BLIST, SIZE_PLEN_BLIST( lenList ) ); - SET_LEN_BLIST(blist, lenList); + Obj blist = NEW_BLIST(LEN_LIST(list)); FuncUNITE_BLIST_LIST(self, list, blist, sub); diff --git a/src/blister.h b/src/blister.h index 376b81bef8..c17f6cda2f 100644 --- a/src/blister.h +++ b/src/blister.h @@ -92,6 +92,21 @@ EXPORT_INLINE void SET_LEN_BLIST(Obj list, Int len) } +/**************************************************************************** +** +*F NEW_BLIST( ) . . . . . . . create new boolean list with given len +** +** returns a new blist with entries, all equal to 'false'. +** +*/ +EXPORT_INLINE Obj NEW_BLIST(Int len) +{ + Obj blist; + blist = NewBag(T_BLIST, SIZE_PLEN_BLIST(len)); + SET_LEN_BLIST(blist, len); + return blist; +} + /**************************************************************************** ** *F BLOCKS_BLIST( ) . . . . . . . . . . first block of a boolean list diff --git a/src/listfunc.c b/src/listfunc.c index f8db3922b6..c4b1818911 100644 --- a/src/listfunc.c +++ b/src/listfunc.c @@ -1422,8 +1422,7 @@ static Obj FuncLIST_WITH_IDENTICAL_ENTRIES(Obj self, Obj n, Obj obj) memset(CHARS_STRING(list), CHAR_VALUE(obj), len); } else if (obj == True || obj == False) { - list = NewBag(T_BLIST, SIZE_PLEN_BLIST(len)); - SET_LEN_BLIST(list, len); + list = NEW_BLIST(len); if (obj == True) { UInt * ptrBlist = BLOCKS_BLIST(list); for (; len >= BIPEB; len -= BIPEB)