Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern Christos was worried about clrbits() being called w...
details: https://anonhg.NetBSD.org/src/rev/22e8e05b0138
branches: trunk
changeset: 749031:22e8e05b0138
user: dsl <dsl%NetBSD.org@localhost>
date: Sat Nov 14 13:18:41 2009 +0000
description:
Christos was worried about clrbits() being called with a length of zero.
This can't happen, but rework so it doesn't matter.
Remove 'optimisation' for length 1, that doesn't happen often enough.
diffstat:
sys/kern/tty_subr.c | 38 +++++++++++++++++---------------------
1 files changed, 17 insertions(+), 21 deletions(-)
diffs (66 lines):
diff -r 3a5eed78fb64 -r 22e8e05b0138 sys/kern/tty_subr.c
--- a/sys/kern/tty_subr.c Sat Nov 14 10:37:27 2009 +0000
+++ b/sys/kern/tty_subr.c Sat Nov 14 13:18:41 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tty_subr.c,v 1.38 2009/11/13 19:15:24 dsl Exp $ */
+/* $NetBSD: tty_subr.c,v 1.39 2009/11/14 13:18:41 dsl Exp $ */
/*
* Copyright (c) 1993, 1994 Theo de Raadt
@@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tty_subr.c,v 1.38 2009/11/13 19:15:24 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tty_subr.c,v 1.39 2009/11/14 13:18:41 dsl Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -303,32 +303,28 @@
static void
clrbits(u_char *cp, unsigned int off, unsigned int len)
{
- unsigned int sby, sbi, eby, ebi;
- unsigned int i;
- u_char mask;
-
- if (len==1) {
- clrbit(cp, off);
- return;
- }
+ unsigned int sbi, ebi;
+ u_char *scp, *ecp;
+ unsigned int end;
+ unsigned char mask;
- len--;
- sby = off / NBBY;
+ scp = cp + off / NBBY;
sbi = off % NBBY;
- eby = (off+len) / NBBY;
- ebi = (off+len) % NBBY + 1;
- if (sby == eby) {
- mask = ((1 << (ebi - sbi)) - 1) << sbi;
- cp[sby] &= ~mask;
+ end = off + len + NBBY - 1;
+ ecp = cp + end / NBBY - 1;
+ ebi = end % NBBY + 1;
+ if (scp >= ecp) {
+ mask = ((1 << len) - 1) << sbi;
+ *scp &= ~mask;
} else {
mask = (1 << sbi) - 1;
- cp[sby++] &= mask;
+ *scp++ &= mask;
mask = (1 << ebi) - 1;
- cp[eby] &= ~mask;
+ *ecp &= ~mask;
- for (i = sby; i < eby; i++)
- cp[i] = 0x00;
+ while (scp < ecp)
+ *scp++ = 0x00;
}
}
#endif
Home |
Main Index |
Thread Index |
Old Index