From 657b5b96df1184ec39abcd047bae7d6faacce52b Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Mon, 28 Apr 2008 17:02:16 -0600 Subject: [PATCH] Whitespace cleanup. * tests/test-strchrnul.c: Reindent. * lib/strchrnul.c: Likewise. Signed-off-by: Eric Blake --- ChangeLog | 4 ++++ lib/strchrnul.c | 24 ++++++++++++------------ tests/test-strchrnul.c | 34 +++++++++++++++++----------------- 3 files changed, 33 insertions(+), 29 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5a3fcbc33a..07baa5eb99 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2008-04-28 Eric Blake + Whitespace cleanup. + * tests/test-strchrnul.c: Reindent. + * lib/strchrnul.c: Likewise. + Optimize and test strchrnul. * lib/strchrnul.c (strchrnul): Rewrite to do parallel search. * modules/strchrnul-tests: New file. diff --git a/lib/strchrnul.c b/lib/strchrnul.c index a5cfcb8f12..0902c18dd4 100644 --- a/lib/strchrnul.c +++ b/lib/strchrnul.c @@ -62,15 +62,15 @@ strchrnul (const char *s, int c_in) repeated_one |= repeated_one << 31 << 1; repeated_c |= repeated_c << 31 << 1; if (8 < sizeof (longword)) - { - size_t i; - - for (i = 64; i < sizeof (longword) * 8; i *= 2) - { - repeated_one |= repeated_one << i; - repeated_c |= repeated_c << i; - } - } + { + size_t i; + + for (i = 64; i < sizeof (longword) * 8; i *= 2) + { + repeated_one |= repeated_one << i; + repeated_c |= repeated_c << i; + } + } } /* Instead of the traditional loop which tests each byte, we will @@ -118,9 +118,9 @@ strchrnul (const char *s, int c_in) longword longword2 = *longword_ptr; if (((((longword1 - repeated_one) & ~longword1) - | ((longword2 - repeated_one) & ~longword2)) - & (repeated_one << 7)) != 0) - break; + | ((longword2 - repeated_one) & ~longword2)) + & (repeated_one << 7)) != 0) + break; longword_ptr++; } diff --git a/tests/test-strchrnul.c b/tests/test-strchrnul.c index fb26535e55..dc550661b4 100644 --- a/tests/test-strchrnul.c +++ b/tests/test-strchrnul.c @@ -25,13 +25,13 @@ #define ASSERT(expr) \ do \ { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - fflush (stderr); \ - abort (); \ - } \ - } \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + fflush (stderr); \ + abort (); \ + } \ + } \ while (0) int @@ -67,7 +67,7 @@ main () size_t repeat = 10000; for (; repeat > 0; repeat--) { - ASSERT (strchrnul (input, 'c') == input + 2); + ASSERT (strchrnul (input, 'c') == input + 2); } } @@ -76,15 +76,15 @@ main () int i, j; for (i = 0; i < 32; i++) { - for (j = 0; j < 256; j++) - input[i + j] = (j + 1) & 0xff; - for (j = 1; j < 256; j++) - { - ASSERT (strchrnul (input + i, j) == input + i + j - 1); - input[i + j - 1] = (j == 1 ? 2 : 1); - ASSERT (strchrnul (input + i, j) == input + i + 255); - input[i + j - 1] = j; - } + for (j = 0; j < 256; j++) + input[i + j] = (j + 1) & 0xff; + for (j = 1; j < 256; j++) + { + ASSERT (strchrnul (input + i, j) == input + i + j - 1); + input[i + j - 1] = (j == 1 ? 2 : 1); + ASSERT (strchrnul (input + i, j) == input + i + 255); + input[i + j - 1] = j; + } } } -- 2.30.2