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.
This commit is contained in:
@@ -9,26 +9,28 @@
|
|||||||
|
|
||||||
/* From Bit twiddling hacks:
|
/* From Bit twiddling hacks:
|
||||||
http://graphics.stanford.edu/~seander/bithacks.html */
|
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
|
size_t
|
||||||
strlen(const char* s)
|
strlen(const char* string)
|
||||||
{
|
{
|
||||||
size_t length = 0;
|
size_t length = 0;
|
||||||
uint32* valuePointer;
|
uint32* valuePointer;
|
||||||
|
|
||||||
/* Align access for four byte reads */
|
/* Align access for four byte reads */
|
||||||
for (; (((addr_t) s + length) & 3) != 0; length++)
|
for (; (((addr_t)string + length) & 3) != 0; length++)
|
||||||
if (s[length] == '\0')
|
if (string[length] == '\0')
|
||||||
return length;
|
return length;
|
||||||
|
|
||||||
/* Check four bytes for zero char */
|
/* Check four bytes for zero char */
|
||||||
for (valuePointer = (uint32*) (s + length); !HasZeroByte(*valuePointer);
|
for (valuePointer = (uint32*)(string + length);
|
||||||
valuePointer++);
|
LACKS_ZERO_BYTE(*valuePointer); valuePointer++);
|
||||||
|
|
||||||
/* Find the exact length */
|
/* Find the exact length */
|
||||||
for (length = ((char*) valuePointer) - s; s[length] != '\0'; length++);
|
for (length = ((char*)valuePointer) - string; string[length] != '\0';
|
||||||
|
length++);
|
||||||
|
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,29 +9,31 @@
|
|||||||
|
|
||||||
/* From Bit twiddling hacks:
|
/* From Bit twiddling hacks:
|
||||||
http://graphics.stanford.edu/~seander/bithacks.html */
|
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
|
size_t
|
||||||
strnlen(const char* s, size_t count)
|
strnlen(const char* string, size_t count)
|
||||||
{
|
{
|
||||||
size_t length = 0;
|
size_t length = 0;
|
||||||
uint32* valuePointer;
|
uint32* valuePointer;
|
||||||
uint32* maxScanPosition;
|
uint32* maxScanPosition;
|
||||||
|
|
||||||
/* Align access for four byte reads */
|
/* Align access for four byte reads */
|
||||||
for (; (((addr_t) s + length) & 3) != 0; length++)
|
for (; (((addr_t)string + length) & 3) != 0; length++)
|
||||||
if (length == count || s[length] == '\0')
|
if (length == count || string[length] == '\0')
|
||||||
return length;
|
return length;
|
||||||
|
|
||||||
/* Check four bytes for zero char */
|
/* Check four bytes for zero char */
|
||||||
maxScanPosition = (uint32*) (s + count - 4);
|
maxScanPosition = (uint32*)(string + count - 4);
|
||||||
for (valuePointer = (uint32*) (s + length); valuePointer <= maxScanPosition
|
for (valuePointer = (uint32*)(string + length);
|
||||||
&& !HasZeroByte(*valuePointer); valuePointer++);
|
valuePointer <= maxScanPosition && LACKS_ZERO_BYTE(*valuePointer);
|
||||||
|
valuePointer++);
|
||||||
|
|
||||||
/* Find the exact length */
|
/* Find the exact length */
|
||||||
for (length = ((char*) valuePointer) - s; length < count
|
for (length = ((char*)valuePointer) - string; length < count
|
||||||
&& s[length] != '\0'; length++);
|
&& string[length] != '\0'; length++);
|
||||||
|
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user