svn commit: r212180 - head/sys/kern

Matthew D Fleming mdf at FreeBSD.org
Fri Sep 3 16:09:17 UTC 2010


Author: mdf
Date: Fri Sep  3 16:09:17 2010
New Revision: 212180
URL: http://svn.freebsd.org/changeset/base/212180

Log:
  Use math rather than iteration when the desired sbuf size is larger than
  SBUF_MAXEXTENDSIZE.

Modified:
  head/sys/kern/subr_sbuf.c

Modified: head/sys/kern/subr_sbuf.c
==============================================================================
--- head/sys/kern/subr_sbuf.c	Fri Sep  3 15:34:28 2010	(r212179)
+++ head/sys/kern/subr_sbuf.c	Fri Sep  3 16:09:17 2010	(r212180)
@@ -116,18 +116,22 @@ _assert_sbuf_state(const char *fun, stru
 
 #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);
 }
 


More information about the svn-src-all mailing list