Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/string Special-case the (unlikely in practice) call...



details:   https://anonhg.NetBSD.org/src/rev/0372f8baaa8e
branches:  trunk
changeset: 760425:0372f8baaa8e
user:      martin <martin%NetBSD.org@localhost>
date:      Tue Jan 04 17:14:07 2011 +0000

description:
Special-case the (unlikely in practice) call with len = 2 - previously
the code would not have swapped anything. Problem pointed out by
sparc64 automatic test run.

diffstat:

 lib/libc/string/swab.c |  10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diffs (31 lines):

diff -r d641b421519a -r 0372f8baaa8e lib/libc/string/swab.c
--- a/lib/libc/string/swab.c    Tue Jan 04 17:00:19 2011 +0000
+++ b/lib/libc/string/swab.c    Tue Jan 04 17:14:07 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: swab.c,v 1.17 2010/04/18 11:39:39 apb Exp $    */
+/*     $NetBSD: swab.c,v 1.18 2011/01/04 17:14:07 martin Exp $ */
 
 /*
  * Copyright (c) 1988, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)swab.c     8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: swab.c,v 1.17 2010/04/18 11:39:39 apb Exp $");
+__RCSID("$NetBSD: swab.c,v 1.18 2011/01/04 17:14:07 martin Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -61,6 +61,12 @@
        fp = (const char *)from;
        tp = (char *)to;
 #define        STEP    temp = *fp++,*tp++ = *fp++,*tp++ = temp
+
+       if (__predict_false(len == 1)) {
+               STEP;
+               return;
+       }
+
        /* round to multiple of 8 */
        while ((--len % 8) != 0)
                STEP;



Home | Main Index | Thread Index | Old Index