From 3111c5c9228f8236e6d699bc4483b659b7949a1f Mon Sep 17 00:00:00 2001 From: Ed Schouten Date: Sun, 21 Sep 2008 18:12:18 +0000 Subject: [PATCH] Now that the number of clist consumers have dropped massively, trim down the code to prevent useless waste of space. - Remove support for quote bits. There is not a single driver that needs these bits anymore. This means putc() now accepts a char instead of an int. - Remove the unneeded catq() and nextc() routines. They were only used by the old TTY layer. - Convert the clist code to use ANSI C prototypes. --- sys/kern/subr_clist.c | 195 +++--------------------------------------- sys/sys/clist.h | 5 +- sys/sys/param.h | 3 +- 3 files changed, 16 insertions(+), 187 deletions(-) diff --git a/sys/kern/subr_clist.c b/sys/kern/subr_clist.c index f434a72bb2a3..65a03b82a18c 100644 --- a/sys/kern/subr_clist.c +++ b/sys/kern/subr_clist.c @@ -52,8 +52,6 @@ static int ctotcount; #define INITIAL_CBLOCKS 50 #endif -#define QUOTEMASK 0x100 - static struct cblock *cblock_alloc(void); static void cblock_alloc_cblocks(int number); static void cblock_free(struct cblock *cblockp); @@ -79,8 +77,7 @@ DB_SHOW_COMMAND(cbstat, cbstat) */ /* ARGSUSED*/ static void -clist_init(dummy) - void *dummy; +clist_init(void *dummy) { /* * Allocate an initial base set of cblocks as a 'slush'. @@ -98,7 +95,7 @@ clist_init(dummy) * to it. */ static __inline struct cblock * -cblock_alloc() +cblock_alloc(void) { struct cblock *cblockp; @@ -115,11 +112,8 @@ cblock_alloc() * Add a cblock to the cfreelist queue. */ static __inline void -cblock_free(cblockp) - struct cblock *cblockp; +cblock_free(struct cblock *cblockp) { - if (isset(cblockp->c_quote, CBQSIZE * NBBY - 1)) - bzero(cblockp->c_quote, sizeof cblockp->c_quote); cblockp->c_next = cfreelist; cfreelist = cblockp; cfreecount += CBSIZE; @@ -129,8 +123,7 @@ cblock_free(cblockp) * Allocate some cblocks for the cfreelist queue. */ static void -cblock_alloc_cblocks(number) - int number; +cblock_alloc_cblocks(int number) { int i; struct cblock *cbp; @@ -146,7 +139,6 @@ cblock_alloc_cblocks(number) * Freed cblocks have zero quotes and garbage elsewhere. * Set the may-have-quote bit to force zeroing the quotes. */ - setbit(cbp->c_quote, CBQSIZE * NBBY - 1); cblock_free(cbp); } ctotcount += number; @@ -157,10 +149,7 @@ cblock_alloc_cblocks(number) * Must be called in process context at spltty(). */ void -clist_alloc_cblocks(clistp, ccmax, ccreserved) - struct clist *clistp; - int ccmax; - int ccreserved; +clist_alloc_cblocks(struct clist *clistp, int ccmax, int ccreserved) { int dcbr; @@ -189,8 +178,7 @@ clist_alloc_cblocks(clistp, ccmax, ccreserved) * system malloc pool. */ static void -cblock_free_cblocks(number) - int number; +cblock_free_cblocks(int number) { int i; @@ -204,8 +192,7 @@ cblock_free_cblocks(number) * Must be called at spltty(). */ void -clist_free_cblocks(clistp) - struct clist *clistp; +clist_free_cblocks(struct clist *clistp) { if (clistp->c_cbcount != 0) panic("freeing active clist cblocks"); @@ -218,8 +205,7 @@ clist_free_cblocks(clistp) * Get a character from the head of a clist. */ int -getc(clistp) - struct clist *clistp; +getc(struct clist *clistp) { int chr = -1; int s; @@ -232,12 +218,6 @@ getc(clistp) cblockp = (struct cblock *)((intptr_t)clistp->c_cf & ~CROUND); chr = (u_char)*clistp->c_cf; - /* - * If this char is quoted, set the flag. - */ - if (isset(cblockp->c_quote, clistp->c_cf - (char *)cblockp->c_info)) - chr |= QUOTEMASK; - /* * Advance to next character. */ @@ -272,10 +252,7 @@ getc(clistp) * actually copied. */ int -q_to_b(clistp, dest, amount) - struct clist *clistp; - char *dest; - int amount; +q_to_b(struct clist *clistp, char *dest, int amount) { struct cblock *cblockp; struct cblock *cblockn; @@ -321,9 +298,7 @@ q_to_b(clistp, dest, amount) * Flush 'amount' of chars, beginning at head of clist 'clistp'. */ void -ndflush(clistp, amount) - struct clist *clistp; - int amount; +ndflush(struct clist *clistp, int amount) { struct cblock *cblockp; struct cblock *cblockn; @@ -366,9 +341,7 @@ ndflush(clistp, amount) * more clists, or 0 for success. */ int -putc(chr, clistp) - int chr; - struct clist *clistp; +putc(char chr, struct clist *clistp) { struct cblock *cblockp; int s; @@ -405,19 +378,6 @@ putc(chr, clistp) } } - /* - * If this character is quoted, set the quote bit, if not, clear it. - */ - if (chr & QUOTEMASK) { - setbit(cblockp->c_quote, clistp->c_cl - (char *)cblockp->c_info); - /* - * Use one of the spare quote bits to record that something - * may be quoted. - */ - setbit(cblockp->c_quote, CBQSIZE * NBBY - 1); - } else - clrbit(cblockp->c_quote, clistp->c_cl - (char *)cblockp->c_info); - *clistp->c_cl++ = chr; clistp->c_cc++; @@ -430,16 +390,10 @@ putc(chr, clistp) * number of characters not copied. */ int -b_to_q(src, amount, clistp) - char *src; - int amount; - struct clist *clistp; +b_to_q(char *src, int amount, struct clist *clistp) { struct cblock *cblockp; - char *firstbyte, *lastbyte; - u_char startmask, endmask; - int startbit, endbit, num_between, numc; - int s; + int numc, s; /* * Avoid allocating an initial cblock and then not using it. @@ -496,39 +450,6 @@ b_to_q(src, amount, clistp) numc = min(amount, (char *)(cblockp + 1) - clistp->c_cl); bcopy(src, clistp->c_cl, numc); - /* - * Clear quote bits if they aren't known to be clear. - * The following could probably be made into a separate - * "bitzero()" routine, but why bother? - */ - if (isset(cblockp->c_quote, CBQSIZE * NBBY - 1)) { - startbit = clistp->c_cl - (char *)cblockp->c_info; - endbit = startbit + numc - 1; - - firstbyte = (u_char *)cblockp->c_quote + (startbit / NBBY); - lastbyte = (u_char *)cblockp->c_quote + (endbit / NBBY); - - /* - * Calculate mask of bits to preserve in first and - * last bytes. - */ - startmask = NBBY - (startbit % NBBY); - startmask = 0xff >> startmask; - endmask = (endbit % NBBY); - endmask = 0xff << (endmask + 1); - - if (firstbyte != lastbyte) { - *firstbyte &= startmask; - *lastbyte &= endmask; - - num_between = lastbyte - firstbyte - 1; - if (num_between) - bzero(firstbyte + 1, num_between); - } else { - *firstbyte &= (startmask | endmask); - } - } - /* * ...and update pointer for the next chunk. */ @@ -551,51 +472,11 @@ b_to_q(src, amount, clistp) return (amount); } -/* - * Get the next character in the clist. Store it at dst. Don't - * advance any clist pointers, but return a pointer to the next - * character position. - */ -char * -nextc(clistp, cp, dst) - struct clist *clistp; - char *cp; - int *dst; -{ - struct cblock *cblockp; - - ++cp; - /* - * See if the next character is beyond the end of - * the clist. - */ - if (clistp->c_cc && (cp != clistp->c_cl)) { - /* - * If the next character is beyond the end of this - * cblock, advance to the next cblock. - */ - if (((intptr_t)cp & CROUND) == 0) - cp = ((struct cblock *)cp - 1)->c_next->c_info; - cblockp = (struct cblock *)((intptr_t)cp & ~CROUND); - - /* - * Get the character. Set the quote flag if this character - * is quoted. - */ - *dst = (u_char)*cp | (isset(cblockp->c_quote, cp - (char *)cblockp->c_info) ? QUOTEMASK : 0); - - return (cp); - } - - return (NULL); -} - /* * "Unput" a character from a clist. */ int -unputc(clistp) - struct clist *clistp; +unputc(struct clist *clistp) { struct cblock *cblockp = 0, *cbp = 0; int s; @@ -612,12 +493,6 @@ unputc(clistp) cblockp = (struct cblock *)((intptr_t)clistp->c_cl & ~CROUND); - /* - * Set quote flag if this character was quoted. - */ - if (isset(cblockp->c_quote, (u_char *)clistp->c_cl - cblockp->c_info)) - chr |= QUOTEMASK; - /* * If all of the characters have been unput in this * cblock, then find the previous one and free this @@ -656,45 +531,3 @@ unputc(clistp) splx(s); return (chr); } - -/* - * Move characters in source clist to destination clist, - * preserving quote bits. - */ -void -catq(src_clistp, dest_clistp) - struct clist *src_clistp, *dest_clistp; -{ - int chr, s; - - s = spltty(); - /* - * If the destination clist is empty (has no cblocks atttached), - * and there are no possible complications with the resource counters, - * then we simply assign the current clist to the destination. - */ - if (!dest_clistp->c_cf - && src_clistp->c_cbcount <= src_clistp->c_cbmax - && src_clistp->c_cbcount <= dest_clistp->c_cbmax) { - dest_clistp->c_cf = src_clistp->c_cf; - dest_clistp->c_cl = src_clistp->c_cl; - src_clistp->c_cf = src_clistp->c_cl = NULL; - - dest_clistp->c_cc = src_clistp->c_cc; - src_clistp->c_cc = 0; - dest_clistp->c_cbcount = src_clistp->c_cbcount; - src_clistp->c_cbcount = 0; - - splx(s); - return; - } - - splx(s); - - /* - * XXX This should probably be optimized to more than one - * character at a time. - */ - while ((chr = getc(src_clistp)) != -1) - putc(chr, dest_clistp); -} diff --git a/sys/sys/clist.h b/sys/sys/clist.h index baf612f4dc48..9f865c8c3767 100644 --- a/sys/sys/clist.h +++ b/sys/sys/clist.h @@ -50,7 +50,6 @@ struct clist { struct cblock { struct cblock *c_next; /* next cblock in queue */ - unsigned char c_quote[CBQSIZE]; /* quoted characters */ unsigned char c_info[CBSIZE]; /* characters */ }; @@ -58,13 +57,11 @@ struct cblock { extern int cfreecount; int b_to_q(char *cp, int cc, struct clist *q); -void catq(struct clist *from, struct clist *to); void clist_alloc_cblocks(struct clist *q, int ccmax, int ccres); void clist_free_cblocks(struct clist *q); int getc(struct clist *q); void ndflush(struct clist *q, int cc); -char *nextc(struct clist *q, char *cp, int *c); -int putc(int c, struct clist *q); +int putc(char c, struct clist *q); int q_to_b(struct clist *q, char *cp, int cc); int unputc(struct clist *q); #endif diff --git a/sys/sys/param.h b/sys/sys/param.h index 316a0009b6c2..c97a5d41be0d 100644 --- a/sys/sys/param.h +++ b/sys/sys/param.h @@ -193,9 +193,8 @@ #define NODEV (dev_t)(-1) /* non-existent device */ #define CBLOCK 128 /* Clist block size, must be a power of 2. */ -#define CBQSIZE (CBLOCK/NBBY) /* Quote bytes/cblock - can do better. */ /* Data chars/clist. */ -#define CBSIZE (CBLOCK - sizeof(struct cblock *) - CBQSIZE) +#define CBSIZE (CBLOCK - sizeof(struct cblock *)) #define CROUND (CBLOCK - 1) /* Clist rounding. */ /*