mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-24 22:10:13 +00:00
tests/string: Drop simple/stupid/builtin tests
In most cases the simple/stupid/builtin functions were in there to benchmark optimized implementations against. Only in some cases the functions are used to check expected results. Remove these tests from IMPL() and only keep them in wherever they're used for a specific purpose, e.g. to generate expected results. This improves timing of `make subdirs=string` by over a minute and a half (over 15%) on a Whiskey Lake laptop. Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org> Reviewed-by: Noah Goldstein <libc-alpha@sourceware.org>
This commit is contained in:
parent
dfc7bf8a24
commit
67e3b0c63c
@ -20,13 +20,9 @@
|
||||
#define TEST_NAME "memccpy"
|
||||
#include "test-string.h"
|
||||
|
||||
void *simple_memccpy (void *, const void *, int, size_t);
|
||||
void *stupid_memccpy (void *, const void *, int, size_t);
|
||||
|
||||
IMPL (stupid_memccpy, 0)
|
||||
IMPL (simple_memccpy, 0)
|
||||
IMPL (memccpy, 1)
|
||||
|
||||
/* Naive implementation to verify results. */
|
||||
void *
|
||||
simple_memccpy (void *dst, const void *src, int c, size_t n)
|
||||
{
|
||||
@ -40,18 +36,6 @@ simple_memccpy (void *dst, const void *src, int c, size_t n)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *
|
||||
stupid_memccpy (void *dst, const void *src, int c, size_t n)
|
||||
{
|
||||
void *p = memchr (src, c, n);
|
||||
|
||||
if (p != NULL)
|
||||
return mempcpy (dst, src, p - src + 1);
|
||||
|
||||
memcpy (dst, src, n);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
typedef void *(*proto_t) (void *, const void *, int c, size_t);
|
||||
|
||||
static void
|
||||
|
@ -44,11 +44,10 @@
|
||||
#endif /* WIDE */
|
||||
|
||||
typedef CHAR *(*proto_t) (const CHAR *, int, size_t);
|
||||
CHAR *SIMPLE_MEMCHR (const CHAR *, int, size_t);
|
||||
|
||||
IMPL (SIMPLE_MEMCHR, 0)
|
||||
IMPL (MEMCHR, 1)
|
||||
|
||||
/* Naive implementation to verify results. */
|
||||
CHAR *
|
||||
SIMPLE_MEMCHR (const CHAR *s, int c, size_t n)
|
||||
{
|
||||
|
@ -85,7 +85,6 @@ SIMPLE_MEMCMP (const char *s1, const char *s2, size_t n)
|
||||
|
||||
typedef int (*proto_t) (const CHAR *, const CHAR *, size_t);
|
||||
|
||||
IMPL (SIMPLE_MEMCMP, 0)
|
||||
IMPL (MEMCMP, 1)
|
||||
|
||||
static int
|
||||
|
@ -29,12 +29,9 @@
|
||||
#define TIMEOUT (8 * 60)
|
||||
#include "test-string.h"
|
||||
|
||||
char *simple_memcpy (char *, const char *, size_t);
|
||||
char *builtin_memcpy (char *, const char *, size_t);
|
||||
|
||||
IMPL (simple_memcpy, 0)
|
||||
IMPL (builtin_memcpy, 0)
|
||||
IMPL (memcpy, 1)
|
||||
|
||||
/* Naive implementation to verify results. */
|
||||
char *
|
||||
simple_memcpy (char *dst, const char *src, size_t n)
|
||||
{
|
||||
@ -44,11 +41,6 @@ simple_memcpy (char *dst, const char *src, size_t n)
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *
|
||||
builtin_memcpy (char *dst, const char *src, size_t n)
|
||||
{
|
||||
return __builtin_memcpy (dst, src, n);
|
||||
}
|
||||
#endif
|
||||
typedef char *(*proto_t) (char *, const char *, size_t);
|
||||
typedef uint32_t __attribute__ ((may_alias, aligned (1))) unaligned_uint32_t;
|
||||
|
@ -23,11 +23,10 @@
|
||||
#include "test-string.h"
|
||||
|
||||
typedef char *(*proto_t) (const void *, size_t, const void *, size_t);
|
||||
void *simple_memmem (const void *, size_t, const void *, size_t);
|
||||
|
||||
IMPL (simple_memmem, 0)
|
||||
IMPL (memmem, 1)
|
||||
|
||||
/* Naive implementation to verify results. */
|
||||
void *
|
||||
simple_memmem (const void *haystack, size_t haystack_len, const void *needle,
|
||||
size_t needle_len)
|
||||
|
@ -29,23 +29,23 @@ char *simple_memmove (char *, const char *, size_t);
|
||||
|
||||
#ifdef TEST_BCOPY
|
||||
typedef void (*proto_t) (const char *, char *, size_t);
|
||||
void simple_bcopy (const char *, char *, size_t);
|
||||
|
||||
IMPL (simple_bcopy, 0)
|
||||
IMPL (bcopy, 1)
|
||||
|
||||
/* Naive implementation to verify results. */
|
||||
void
|
||||
simple_bcopy (const char *src, char *dst, size_t n)
|
||||
{
|
||||
simple_memmove (dst, src, n);
|
||||
}
|
||||
|
||||
#else
|
||||
typedef char *(*proto_t) (char *, const char *, size_t);
|
||||
|
||||
IMPL (simple_memmove, 0)
|
||||
IMPL (memmove, 1)
|
||||
#endif
|
||||
|
||||
/* Naive implementation to verify results. */
|
||||
char *
|
||||
inhibit_loop_to_libcall
|
||||
simple_memmove (char *dst, const char *src, size_t n)
|
||||
|
@ -22,11 +22,9 @@
|
||||
#define TEST_NAME "mempcpy"
|
||||
#include "test-string.h"
|
||||
|
||||
char *simple_mempcpy (char *, const char *, size_t);
|
||||
|
||||
IMPL (simple_mempcpy, 0)
|
||||
IMPL (mempcpy, 1)
|
||||
|
||||
/* Naive implementation to verify results. */
|
||||
char *
|
||||
simple_mempcpy (char *dst, const char *src, size_t n)
|
||||
{
|
||||
|
@ -21,11 +21,10 @@
|
||||
#include "test-string.h"
|
||||
|
||||
typedef char *(*proto_t) (const char *, int, size_t);
|
||||
char *simple_memrchr (const char *, int, size_t);
|
||||
|
||||
IMPL (simple_memrchr, 0)
|
||||
IMPL (memrchr, 1)
|
||||
|
||||
/* Naive implementation to verify results. */
|
||||
char *
|
||||
simple_memrchr (const char *s, int c, size_t n)
|
||||
{
|
||||
|
@ -50,51 +50,19 @@
|
||||
# define BIG_CHAR WCHAR_MAX
|
||||
#endif /* WIDE */
|
||||
|
||||
CHAR *SIMPLE_MEMSET (CHAR *, int, size_t);
|
||||
|
||||
#ifdef TEST_BZERO
|
||||
typedef void (*proto_t) (char *, size_t);
|
||||
void simple_bzero (char *, size_t);
|
||||
void builtin_bzero (char *, size_t);
|
||||
|
||||
IMPL (simple_bzero, 0)
|
||||
IMPL (builtin_bzero, 0)
|
||||
#ifdef TEST_EXPLICIT_BZERO
|
||||
# ifdef TEST_EXPLICIT_BZERO
|
||||
IMPL (explicit_bzero, 1)
|
||||
#else
|
||||
# else
|
||||
IMPL (bzero, 1)
|
||||
#endif
|
||||
|
||||
void
|
||||
simple_bzero (char *s, size_t n)
|
||||
{
|
||||
SIMPLE_MEMSET (s, 0, n);
|
||||
}
|
||||
|
||||
void
|
||||
builtin_bzero (char *s, size_t n)
|
||||
{
|
||||
__builtin_bzero (s, n);
|
||||
}
|
||||
# endif
|
||||
#else
|
||||
typedef CHAR *(*proto_t) (CHAR *, int, size_t);
|
||||
|
||||
IMPL (SIMPLE_MEMSET, 0)
|
||||
# ifndef WIDE
|
||||
char *builtin_memset (char *, int, size_t);
|
||||
IMPL (builtin_memset, 0)
|
||||
# endif /* !WIDE */
|
||||
IMPL (MEMSET, 1)
|
||||
|
||||
# ifndef WIDE
|
||||
char *
|
||||
builtin_memset (char *s, int c, size_t n)
|
||||
{
|
||||
return __builtin_memset (s, c, n);
|
||||
}
|
||||
# endif /* !WIDE */
|
||||
#endif /* !TEST_BZERO */
|
||||
|
||||
/* Naive implementation to verify results. */
|
||||
CHAR *
|
||||
inhibit_loop_to_libcall
|
||||
SIMPLE_MEMSET (CHAR *s, int c, size_t n)
|
||||
@ -116,7 +84,7 @@ do_one_test (impl_t *impl, CHAR *s, int c __attribute ((unused)), size_t n, int
|
||||
s[n] = sentinel;
|
||||
SIMPLE_MEMSET(s, ~c, n);
|
||||
#ifdef TEST_BZERO
|
||||
simple_bzero (buf, n);
|
||||
SIMPLE_MEMSET (buf, 0, n);
|
||||
CALL (impl, s, n);
|
||||
if (memcmp (s, buf, n) != 0
|
||||
|| (space_below && s[-1] != sentinel)
|
||||
|
@ -27,14 +27,11 @@
|
||||
#include "test-string.h"
|
||||
|
||||
typedef int (*proto_t) (const char *, const char *);
|
||||
static int simple_strcasecmp (const char *, const char *);
|
||||
static int stupid_strcasecmp (const char *, const char *);
|
||||
|
||||
IMPL (stupid_strcasecmp, 0)
|
||||
IMPL (simple_strcasecmp, 0)
|
||||
IMPL (strcasecmp, 1)
|
||||
|
||||
static int
|
||||
/* Naive implementation to verify results. */
|
||||
int
|
||||
simple_strcasecmp (const char *s1, const char *s2)
|
||||
{
|
||||
int ret;
|
||||
@ -46,24 +43,6 @@ simple_strcasecmp (const char *s1, const char *s2)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
stupid_strcasecmp (const char *s1, const char *s2)
|
||||
{
|
||||
size_t ns1 = strlen (s1) + 1, ns2 = strlen (s2) + 1;
|
||||
size_t n = ns1 < ns2 ? ns1 : ns2;
|
||||
int ret = 0;
|
||||
|
||||
while (n--)
|
||||
{
|
||||
if ((ret = ((unsigned char) tolower (*s1)
|
||||
- (unsigned char) tolower (*s2))) != 0)
|
||||
break;
|
||||
++s1;
|
||||
++s2;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void
|
||||
do_one_test (impl_t *impl, const char *s1, const char *s2, int exp_result)
|
||||
{
|
||||
|
@ -21,15 +21,15 @@
|
||||
#include "test-string.h"
|
||||
|
||||
|
||||
#define STRCASESTR simple_strcasestr
|
||||
#define STRCASESTR c_strcasestr
|
||||
#define NO_ALIAS
|
||||
#define __strncasecmp strncasecmp
|
||||
#define __strnlen strnlen
|
||||
#include "strcasestr.c"
|
||||
|
||||
|
||||
/* Naive implementation to verify results. */
|
||||
static char *
|
||||
stupid_strcasestr (const char *s1, const char *s2)
|
||||
simple_strcasestr (const char *s1, const char *s2)
|
||||
{
|
||||
ssize_t s1len = strlen (s1);
|
||||
ssize_t s2len = strlen (s2);
|
||||
@ -53,8 +53,7 @@ stupid_strcasestr (const char *s1, const char *s2)
|
||||
|
||||
typedef char *(*proto_t) (const char *, const char *);
|
||||
|
||||
IMPL (stupid_strcasestr, 0)
|
||||
IMPL (simple_strcasestr, 0)
|
||||
IMPL (c_strcasestr, 0)
|
||||
IMPL (strcasestr, 1)
|
||||
|
||||
|
||||
@ -129,7 +128,7 @@ check1 (void)
|
||||
const char s2[] = "OK";
|
||||
char *exp_result;
|
||||
|
||||
exp_result = stupid_strcasestr (s1, s2);
|
||||
exp_result = simple_strcasestr (s1, s2);
|
||||
FOR_EACH_IMPL (impl, 0)
|
||||
check_result (impl, s1, s2, exp_result);
|
||||
}
|
||||
|
@ -54,11 +54,10 @@
|
||||
#endif /* WIDE */
|
||||
|
||||
typedef CHAR *(*proto_t) (CHAR *, const CHAR *);
|
||||
CHAR *SIMPLE_STRCAT (CHAR *, const CHAR *);
|
||||
|
||||
IMPL (SIMPLE_STRCAT, 0)
|
||||
IMPL (STRCAT, 1)
|
||||
|
||||
/* Naive implementation to verify results. */
|
||||
CHAR *
|
||||
SIMPLE_STRCAT (CHAR *dst, const CHAR *src)
|
||||
{
|
||||
|
@ -35,7 +35,6 @@
|
||||
#ifndef WIDE
|
||||
# ifdef USE_FOR_STRCHRNUL
|
||||
# define STRCHR strchrnul
|
||||
# define stupid_STRCHR stupid_STRCHRNUL
|
||||
# define simple_STRCHR simple_STRCHRNUL
|
||||
# else
|
||||
# define STRCHR strchr
|
||||
@ -51,7 +50,6 @@
|
||||
# include <wchar.h>
|
||||
# ifdef USE_FOR_STRCHRNUL
|
||||
# define STRCHR wcschrnul
|
||||
# define stupid_STRCHR stupid_WCSCHRNUL
|
||||
# define simple_STRCHR simple_WCSCHRNUL
|
||||
# else
|
||||
# define STRCHR wcschr
|
||||
@ -74,17 +72,9 @@
|
||||
|
||||
typedef CHAR *(*proto_t) (const CHAR *, int);
|
||||
|
||||
/* Naive implementation to verify results. */
|
||||
CHAR *
|
||||
simple_STRCHR (const CHAR *s, int c)
|
||||
{
|
||||
for (; *s != (CHAR) c; ++s)
|
||||
if (*s == '\0')
|
||||
return NULLRET ((CHAR *) s);
|
||||
return (CHAR *) s;
|
||||
}
|
||||
|
||||
CHAR *
|
||||
stupid_STRCHR (const CHAR *s, int c)
|
||||
{
|
||||
size_t n = STRLEN (s) + 1;
|
||||
|
||||
@ -94,8 +84,6 @@ stupid_STRCHR (const CHAR *s, int c)
|
||||
return NULLRET ((CHAR *) s - 1);
|
||||
}
|
||||
|
||||
IMPL (stupid_STRCHR, 0)
|
||||
IMPL (simple_STRCHR, 0)
|
||||
IMPL (STRCHR, 1)
|
||||
|
||||
static int
|
||||
@ -231,7 +219,7 @@ check1 (void)
|
||||
{
|
||||
CHAR s[] __attribute__((aligned(16))) = L ("\xff");
|
||||
CHAR c = L ('\xfe');
|
||||
CHAR *exp_result = stupid_STRCHR (s, c);
|
||||
CHAR *exp_result = simple_STRCHR (s, c);
|
||||
|
||||
FOR_EACH_IMPL (impl, 0)
|
||||
check_result (impl, s, c, exp_result);
|
||||
|
@ -99,7 +99,6 @@ simple_strcmp (const char *s1, const char *s2)
|
||||
|
||||
typedef int (*proto_t) (const CHAR *, const CHAR *);
|
||||
|
||||
IMPL (SIMPLE_STRCMP, 1)
|
||||
IMPL (STRCMP, 1)
|
||||
|
||||
static int
|
||||
|
@ -54,11 +54,9 @@
|
||||
# define STRCPY wcscpy
|
||||
# endif
|
||||
|
||||
CHAR *SIMPLE_STRCPY (CHAR *, const CHAR *);
|
||||
|
||||
IMPL (SIMPLE_STRCPY, 0)
|
||||
IMPL (STRCPY, 1)
|
||||
|
||||
/* Naive implementation to verify results. */
|
||||
CHAR *
|
||||
SIMPLE_STRCPY (CHAR *dst, const CHAR *src)
|
||||
{
|
||||
|
@ -37,6 +37,7 @@
|
||||
|
||||
typedef size_t (*proto_t) (const CHAR *);
|
||||
|
||||
/* Naive implementation to verify results. */
|
||||
size_t
|
||||
simple_STRLEN (const CHAR *s)
|
||||
{
|
||||
@ -55,7 +56,6 @@ builtin_strlen (const CHAR *p)
|
||||
IMPL (builtin_strlen, 0)
|
||||
#endif
|
||||
|
||||
IMPL (simple_STRLEN, 0)
|
||||
IMPL (STRLEN, 1)
|
||||
|
||||
|
||||
|
@ -29,12 +29,10 @@
|
||||
|
||||
typedef int (*proto_t) (const char *, const char *, size_t);
|
||||
static int simple_strncasecmp (const char *, const char *, size_t);
|
||||
static int stupid_strncasecmp (const char *, const char *, size_t);
|
||||
|
||||
IMPL (stupid_strncasecmp, 0)
|
||||
IMPL (simple_strncasecmp, 0)
|
||||
IMPL (strncasecmp, 1)
|
||||
|
||||
/* Naive implementation to verify results. */
|
||||
static int
|
||||
simple_strncasecmp (const char *s1, const char *s2, size_t n)
|
||||
{
|
||||
@ -54,27 +52,6 @@ simple_strncasecmp (const char *s1, const char *s2, size_t n)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
stupid_strncasecmp (const char *s1, const char *s2, size_t max)
|
||||
{
|
||||
size_t ns1 = strlen (s1) + 1;
|
||||
size_t ns2 = strlen (s2) + 1;
|
||||
size_t n = ns1 < ns2 ? ns1 : ns2;
|
||||
if (n > max)
|
||||
n = max;
|
||||
int ret = 0;
|
||||
|
||||
while (n--)
|
||||
{
|
||||
if ((ret = ((unsigned char) tolower (*s1)
|
||||
- (unsigned char) tolower (*s2))) != 0)
|
||||
break;
|
||||
++s1;
|
||||
++s2;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
check_result (impl_t *impl, const char *s1, const char *s2, size_t n,
|
||||
int exp_result)
|
||||
|
@ -28,7 +28,6 @@
|
||||
# define CHAR char
|
||||
# define UCHAR unsigned char
|
||||
# define SIMPLE_STRNCAT simple_strncat
|
||||
# define STUPID_STRNCAT stupid_strncat
|
||||
# define STRLEN strlen
|
||||
# define MEMSET memset
|
||||
# define MEMCPY memcpy
|
||||
@ -41,7 +40,6 @@
|
||||
# define CHAR wchar_t
|
||||
# define UCHAR wchar_t
|
||||
# define SIMPLE_STRNCAT simple_wcsncat
|
||||
# define STUPID_STRNCAT stupid_wcsncat
|
||||
# define STRLEN wcslen
|
||||
# define MEMSET wmemset
|
||||
# define MEMCPY wmemcpy
|
||||
@ -51,14 +49,12 @@
|
||||
#endif /* WIDE */
|
||||
|
||||
typedef CHAR *(*proto_t) (CHAR *, const CHAR *, size_t);
|
||||
CHAR *STUPID_STRNCAT (CHAR *, const CHAR *, size_t);
|
||||
CHAR *SIMPLE_STRNCAT (CHAR *, const CHAR *, size_t);
|
||||
|
||||
IMPL (STUPID_STRNCAT, 0)
|
||||
IMPL (STRNCAT, 2)
|
||||
|
||||
/* Naive implementation to verify results. */
|
||||
CHAR *
|
||||
STUPID_STRNCAT (CHAR *dst, const CHAR *src, size_t n)
|
||||
SIMPLE_STRNCAT (CHAR *dst, const CHAR *src, size_t n)
|
||||
{
|
||||
CHAR *ret = dst;
|
||||
while (*dst++ != '\0');
|
||||
|
@ -88,7 +88,6 @@ simple_strncmp (const char *s1, const char *s2, size_t n)
|
||||
|
||||
typedef int (*proto_t) (const CHAR *, const CHAR *, size_t);
|
||||
|
||||
IMPL (SIMPLE_STRNCMP, 0)
|
||||
IMPL (STRNCMP, 1)
|
||||
|
||||
|
||||
|
@ -47,21 +47,16 @@
|
||||
# include "test-string.h"
|
||||
# ifndef WIDE
|
||||
# define SIMPLE_STRNCPY simple_strncpy
|
||||
# define STUPID_STRNCPY stupid_strncpy
|
||||
# define STRNCPY strncpy
|
||||
# else
|
||||
# define SIMPLE_STRNCPY simple_wcsncpy
|
||||
# define STUPID_STRNCPY stupid_wcsncpy
|
||||
# define STRNCPY wcsncpy
|
||||
# endif /* WIDE */
|
||||
|
||||
CHAR *SIMPLE_STRNCPY (CHAR *, const CHAR *, size_t);
|
||||
CHAR *STUPID_STRNCPY (CHAR *, const CHAR *, size_t);
|
||||
|
||||
IMPL (STUPID_STRNCPY, 0)
|
||||
IMPL (SIMPLE_STRNCPY, 0)
|
||||
IMPL (STRNCPY, 1)
|
||||
|
||||
/* Naive implementation to verify results. */
|
||||
CHAR *
|
||||
SIMPLE_STRNCPY (CHAR *dst, const CHAR *src, size_t n)
|
||||
{
|
||||
@ -76,18 +71,6 @@ SIMPLE_STRNCPY (CHAR *dst, const CHAR *src, size_t n)
|
||||
return ret;
|
||||
}
|
||||
|
||||
CHAR *
|
||||
STUPID_STRNCPY (CHAR *dst, const CHAR *src, size_t n)
|
||||
{
|
||||
size_t nc = STRNLEN (src, n);
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < nc; ++i)
|
||||
dst[i] = src[i];
|
||||
for (; i < n; ++i)
|
||||
dst[i] = '\0';
|
||||
return dst;
|
||||
}
|
||||
#endif /* !STRNCPY_RESULT */
|
||||
|
||||
typedef CHAR *(*proto_t) (CHAR *, const CHAR *, size_t);
|
||||
|
@ -42,11 +42,10 @@
|
||||
#endif /* !WIDE */
|
||||
|
||||
typedef size_t (*proto_t) (const CHAR *, size_t);
|
||||
size_t SIMPLE_STRNLEN (const CHAR *, size_t);
|
||||
|
||||
IMPL (SIMPLE_STRNLEN, 0)
|
||||
IMPL (STRNLEN, 1)
|
||||
|
||||
/* Naive implementation to verify results. */
|
||||
size_t
|
||||
SIMPLE_STRNLEN (const CHAR *s, size_t maxlen)
|
||||
{
|
||||
|
@ -47,22 +47,17 @@
|
||||
# ifndef WIDE
|
||||
# define STRPBRK strpbrk
|
||||
# define SIMPLE_STRPBRK simple_strpbrk
|
||||
# define STUPID_STRPBRK stupid_strpbrk
|
||||
# else
|
||||
# include <wchar.h>
|
||||
# define STRPBRK wcspbrk
|
||||
# define SIMPLE_STRPBRK simple_wcspbrk
|
||||
# define STUPID_STRPBRK stupid_wcspbrk
|
||||
# endif /* WIDE */
|
||||
|
||||
typedef CHAR *(*proto_t) (const CHAR *, const CHAR *);
|
||||
CHAR *SIMPLE_STRPBRK (const CHAR *, const CHAR *);
|
||||
CHAR *STUPID_STRPBRK (const CHAR *, const CHAR *);
|
||||
|
||||
IMPL (STUPID_STRPBRK, 0)
|
||||
IMPL (SIMPLE_STRPBRK, 0)
|
||||
IMPL (STRPBRK, 1)
|
||||
|
||||
/* Naive implementation to verify results. */
|
||||
CHAR *
|
||||
SIMPLE_STRPBRK (const CHAR *s, const CHAR *rej)
|
||||
{
|
||||
@ -72,22 +67,10 @@ SIMPLE_STRPBRK (const CHAR *s, const CHAR *rej)
|
||||
while ((c = *s++) != '\0')
|
||||
for (r = rej; *r != '\0'; ++r)
|
||||
if (*r == c)
|
||||
return (CHAR *) s - 1;
|
||||
return (CHAR *) s - 1;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CHAR *
|
||||
STUPID_STRPBRK (const CHAR *s, const CHAR *rej)
|
||||
{
|
||||
size_t ns = STRLEN (s), nrej = STRLEN (rej);
|
||||
size_t i, j;
|
||||
|
||||
for (i = 0; i < ns; ++i)
|
||||
for (j = 0; j < nrej; ++j)
|
||||
if (s[i] == rej[j])
|
||||
return (CHAR *) s + i;
|
||||
return NULL;
|
||||
}
|
||||
#endif /* !STRPBRK_RESULT */
|
||||
|
||||
static void
|
||||
|
@ -42,11 +42,10 @@
|
||||
#endif
|
||||
|
||||
typedef CHAR *(*proto_t) (const CHAR *, int);
|
||||
CHAR *SIMPLE_STRRCHR (const CHAR *, int);
|
||||
|
||||
IMPL (SIMPLE_STRRCHR, 0)
|
||||
IMPL (STRRCHR, 1)
|
||||
|
||||
/* Naive implementation to verify results. */
|
||||
CHAR *
|
||||
SIMPLE_STRRCHR (const CHAR *s, int c)
|
||||
{
|
||||
|
@ -29,7 +29,6 @@
|
||||
# define CHAR char
|
||||
# define UCHAR unsigned char
|
||||
# define SIMPLE_STRSPN simple_strspn
|
||||
# define STUPID_STRSPN stupid_strspn
|
||||
# define STRLEN strlen
|
||||
# define STRCHR strchr
|
||||
# define BIG_CHAR CHAR_MAX
|
||||
@ -40,7 +39,6 @@
|
||||
# define CHAR wchar_t
|
||||
# define UCHAR wchar_t
|
||||
# define SIMPLE_STRSPN simple_wcsspn
|
||||
# define STUPID_STRSPN stupid_wcsspn
|
||||
# define STRLEN wcslen
|
||||
# define STRCHR wcschr
|
||||
# define BIG_CHAR WCHAR_MAX
|
||||
@ -48,13 +46,10 @@
|
||||
#endif /* WIDE */
|
||||
|
||||
typedef size_t (*proto_t) (const CHAR *, const CHAR *);
|
||||
size_t SIMPLE_STRSPN (const CHAR *, const CHAR *);
|
||||
size_t STUPID_STRSPN (const CHAR *, const CHAR *);
|
||||
|
||||
IMPL (STUPID_STRSPN, 0)
|
||||
IMPL (SIMPLE_STRSPN, 0)
|
||||
IMPL (STRSPN, 1)
|
||||
|
||||
/* Naive implementation to verify results. */
|
||||
size_t
|
||||
SIMPLE_STRSPN (const CHAR *s, const CHAR *acc)
|
||||
{
|
||||
@ -72,23 +67,6 @@ SIMPLE_STRSPN (const CHAR *s, const CHAR *acc)
|
||||
return s - str - 1;
|
||||
}
|
||||
|
||||
size_t
|
||||
STUPID_STRSPN (const CHAR *s, const CHAR *acc)
|
||||
{
|
||||
size_t ns = STRLEN (s), nacc = STRLEN (acc);
|
||||
size_t i, j;
|
||||
|
||||
for (i = 0; i < ns; ++i)
|
||||
{
|
||||
for (j = 0; j < nacc; ++j)
|
||||
if (s[i] == acc[j])
|
||||
break;
|
||||
if (j == nacc)
|
||||
return i;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
static void
|
||||
do_one_test (impl_t *impl, const CHAR *s, const CHAR *acc, size_t exp_res)
|
||||
{
|
||||
|
@ -21,14 +21,14 @@
|
||||
#include "test-string.h"
|
||||
|
||||
|
||||
#define STRSTR simple_strstr
|
||||
#define STRSTR c_strstr
|
||||
#define libc_hidden_builtin_def(arg) /* nothing */
|
||||
#define __strnlen strnlen
|
||||
#include "strstr.c"
|
||||
|
||||
|
||||
/* Naive implementation to verify results. */
|
||||
static char *
|
||||
stupid_strstr (const char *s1, const char *s2)
|
||||
simple_strstr (const char *s1, const char *s2)
|
||||
{
|
||||
ssize_t s1len = strlen (s1);
|
||||
ssize_t s2len = strlen (s2);
|
||||
@ -52,8 +52,7 @@ stupid_strstr (const char *s1, const char *s2)
|
||||
|
||||
typedef char *(*proto_t) (const char *, const char *);
|
||||
|
||||
IMPL (stupid_strstr, 0)
|
||||
IMPL (simple_strstr, 0)
|
||||
IMPL (c_strstr, 0)
|
||||
IMPL (strstr, 1)
|
||||
|
||||
|
||||
@ -130,7 +129,7 @@ check1 (void)
|
||||
const char s2[] = "_EF_BF_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD";
|
||||
char *exp_result;
|
||||
|
||||
exp_result = stupid_strstr (s1, s2);
|
||||
exp_result = simple_strstr (s1, s2);
|
||||
FOR_EACH_IMPL (impl, 0)
|
||||
check_result (impl, s1, s2, exp_result);
|
||||
}
|
||||
@ -163,7 +162,7 @@ check2 (void)
|
||||
char *s2_page_cross = (void *) buf2 + page_size_real - 8;
|
||||
strcpy (s2_page_cross, s2_stack);
|
||||
|
||||
exp_result = stupid_strstr (s1_stack, s2_stack);
|
||||
exp_result = simple_strstr (s1_stack, s2_stack);
|
||||
FOR_EACH_IMPL (impl, 0)
|
||||
{
|
||||
check_result (impl, s1_stack, s2_stack, exp_result);
|
||||
@ -201,7 +200,7 @@ pr23637 (void)
|
||||
/* Ensure we don't match at the first 'x'. */
|
||||
h[0] = 'x';
|
||||
|
||||
char *exp_result = stupid_strstr (h, n);
|
||||
char *exp_result = simple_strstr (h, n);
|
||||
FOR_EACH_IMPL (impl, 0)
|
||||
check_result (impl, h, n, exp_result);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user