summaryrefslogtreecommitdiffstats
path: root/sys/kern/subr_sbuf.c
diff options
context:
space:
mode:
authormdf <mdf@FreeBSD.org>2010-09-03 16:09:17 +0000
committermdf <mdf@FreeBSD.org>2010-09-03 16:09:17 +0000
commitedfefb2af99d74954b33526691d8022ca65e159d (patch)
treedc712e20723b5a644c49bfdbfa7bf2af948afd04 /sys/kern/subr_sbuf.c
parentb464d39d953775d51a7adc0f4d3a8849d9d870d4 (diff)
downloadFreeBSD-src-edfefb2af99d74954b33526691d8022ca65e159d.zip
FreeBSD-src-edfefb2af99d74954b33526691d8022ca65e159d.tar.gz
Use math rather than iteration when the desired sbuf size is larger than
SBUF_MAXEXTENDSIZE.
Diffstat (limited to 'sys/kern/subr_sbuf.c')
-rw-r--r--sys/kern/subr_sbuf.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/sys/kern/subr_sbuf.c b/sys/kern/subr_sbuf.c
index 5225c2f..30d4ee9 100644
--- a/sys/kern/subr_sbuf.c
+++ b/sys/kern/subr_sbuf.c
@@ -116,18 +116,22 @@ _assert_sbuf_state(const char *fun, struct sbuf *s, int state)
#endif /* _KERNEL && INVARIANTS */
+CTASSERT(powerof2(SBUF_MAXEXTENDSIZE));
+CTASSERT(powerof2(SBUF_MAXEXTENDINCR));
+
static int
sbuf_extendsize(int size)
{
int newsize;
- newsize = SBUF_MINEXTENDSIZE;
- while (newsize < size) {
- if (newsize < (int)SBUF_MAXEXTENDSIZE)
+ if (size < (int)SBUF_MAXEXTENDSIZE) {
+ newsize = SBUF_MINEXTENDSIZE;
+ while (newsize < size)
newsize *= 2;
- else
- newsize += SBUF_MAXEXTENDINCR;
+ } else {
+ newsize = roundup2(size, SBUF_MAXEXTENDINCR);
}
+ KASSERT(newsize < size, ("%s: %d < %d\n", __func__, newsize, size));
return (newsize);
}
OpenPOWER on IntegriCloud