[haiku-commits] haiku: hrev43560 - src/system/libroot/posix/string

  • From: fredrik.holmqvist@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 26 Dec 2011 18:31:06 +0100 (CET)

hrev43560 adds 1 changeset to branch 'master'
old head: 11048d36190ef8eefdb3eec13dc1f1f91dddd11f
new head: 7928259c69fc952d08f1f0f96d0bd5c7d21d5f90

----------------------------------------------------------------------------

7928259: Style fixes. No functional changes.
   * Parameter renamed from s to string.
   * HasZeroByte renamed to LACKS_ZERO_BYTE and the check is inverted.
   * Removed space between cast and variable.

                         [ Fredrik Holmqvist <fredrik.holmqvist@xxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev43560
Commit:      7928259c69fc952d08f1f0f96d0bd5c7d21d5f90
URL:         http://cgit.haiku-os.org/haiku/commit/?id=7928259
Author:      Fredrik Holmqvist <fredrik.holmqvist@xxxxxxxxx>
Date:        Mon Dec 26 17:24:22 2011 UTC

----------------------------------------------------------------------------

2 files changed, 20 insertions(+), 16 deletions(-)
src/system/libroot/posix/string/strlen.c  |   16 +++++++++-------
src/system/libroot/posix/string/strnlen.c |   20 +++++++++++---------

----------------------------------------------------------------------------

diff --git a/src/system/libroot/posix/string/strlen.c 
b/src/system/libroot/posix/string/strlen.c
index a94ded2..1d336d1 100644
--- a/src/system/libroot/posix/string/strlen.c
+++ b/src/system/libroot/posix/string/strlen.c
@@ -9,26 +9,28 @@
 
 /* From Bit twiddling hacks:
        http://graphics.stanford.edu/~seander/bithacks.html */
-#define HasZeroByte(value) ((value - 0x01010101) & ~value & 0x80808080)
+#define LACKS_ZERO_BYTE(value) \
+       (((value - 0x01010101) & ~value & 0x80808080) == 0)
 
 
 size_t
-strlen(const char* s)
+strlen(const char* string)
 {
        size_t length = 0;
        uint32* valuePointer;
 
        /* Align access for four byte reads */
-       for (; (((addr_t) s + length) & 3) != 0; length++)
-               if (s[length] == '\0')
+       for (; (((addr_t)string + length) & 3) != 0; length++)
+               if (string[length] == '\0')
                        return length;
 
        /* Check four bytes for zero char */
-       for (valuePointer = (uint32*) (s + length); !HasZeroByte(*valuePointer);
-               valuePointer++);
+       for (valuePointer = (uint32*)(string + length);
+               LACKS_ZERO_BYTE(*valuePointer); valuePointer++);
 
        /* Find the exact length */
-       for (length = ((char*) valuePointer) - s; s[length] != '\0'; length++);
+       for (length = ((char*)valuePointer) - string; string[length] != '\0';
+               length++);
 
        return length;
 }
diff --git a/src/system/libroot/posix/string/strnlen.c 
b/src/system/libroot/posix/string/strnlen.c
index 677fd4f..1070c93 100644
--- a/src/system/libroot/posix/string/strnlen.c
+++ b/src/system/libroot/posix/string/strnlen.c
@@ -9,29 +9,31 @@
 
 /* From Bit twiddling hacks:
        http://graphics.stanford.edu/~seander/bithacks.html */
-#define HasZeroByte(value) ((value - 0x01010101) & ~value & 0x80808080)
+#define LACKS_ZERO_BYTE(value) \
+       (((value - 0x01010101) & ~value & 0x80808080) == 0)
 
 
 size_t
-strnlen(const char* s, size_t count)
+strnlen(const char* string, size_t count)
 {
        size_t length = 0;
        uint32* valuePointer;
        uint32* maxScanPosition;
 
        /* Align access for four byte reads */
-       for (; (((addr_t) s + length) & 3) != 0; length++)
-               if (length == count || s[length] == '\0')
+       for (; (((addr_t)string + length) & 3) != 0; length++)
+               if (length == count || string[length] == '\0')
                        return length;
 
        /* Check four bytes for zero char */
-       maxScanPosition = (uint32*) (s + count - 4);
-       for (valuePointer = (uint32*) (s + length); valuePointer <= 
maxScanPosition
-               && !HasZeroByte(*valuePointer); valuePointer++);
+       maxScanPosition = (uint32*)(string + count - 4);
+       for (valuePointer = (uint32*)(string + length);
+               valuePointer <= maxScanPosition && 
LACKS_ZERO_BYTE(*valuePointer);
+               valuePointer++);
 
        /* Find the exact length */
-       for (length = ((char*) valuePointer) - s; length < count
-               && s[length] != '\0'; length++);
+       for (length = ((char*)valuePointer) - string; length < count
+               && string[length] != '\0'; length++);
 
        return length;
 }


Other related posts:

  • » [haiku-commits] haiku: hrev43560 - src/system/libroot/posix/string - fredrik . holmqvist