From 24fb0f88ed29d21b6034559e9c55545f22556bc0 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Mon, 26 Jul 2010 08:37:08 -0700 Subject: Add optimized x86-64 implementation of strnlen. While at it, beef up the test suite for strnlen and add performance tests for it, too. --- string/tester.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'string/tester.c') diff --git a/string/tester.c b/string/tester.c index 773e969a35..01da0465da 100644 --- a/string/tester.c +++ b/string/tester.c @@ -1,5 +1,5 @@ /* Tester for string functions. - Copyright (C) 1995-2001, 2003, 2005, 2008 Free Software Foundation, Inc. + Copyright (C) 1995-2001, 2003, 2005, 2008, 2010 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -441,20 +441,21 @@ test_strnlen (void) check (strnlen ("", 10) == 0, 1); /* Empty. */ check (strnlen ("a", 10) == 1, 2); /* Single char. */ check (strnlen ("abcd", 10) == 4, 3); /* Multiple chars. */ - check (strnlen ("foo", (size_t)-1) == 3, 4); /* limits of n. */ - - { - char buf[4096]; - int i; - char *p; - for (i=0; i < 0x100; i++) - { - p = (char *) ((unsigned long int)(buf + 0xff) & ~0xff) + i; - strcpy (p, "OK"); - strcpy (p+3, "BAD/WRONG"); - check (strnlen (p, 100) == 2, 5+i); - } - } + check (strnlen ("foo", (size_t) -1) == 3, 4); /* limits of n. */ + check (strnlen ("abcd", 0) == 0, 5); /* Restricted. */ + check (strnlen ("abcd", 1) == 1, 6); /* Restricted. */ + check (strnlen ("abcd", 2) == 2, 7); /* Restricted. */ + check (strnlen ("abcd", 3) == 3, 8); /* Restricted. */ + check (strnlen ("abcd", 4) == 4, 9); /* Restricted. */ + + char buf[4096]; + for (int i = 0; i < 0x100; ++i) + { + char *p = (char *) ((unsigned long int)(buf + 0xff) & ~0xff) + i; + strcpy (p, "OK"); + strcpy (p + 3, "BAD/WRONG"); + check (strnlen (p, 100) == 2, 10 + i); + } } static void @@ -988,7 +989,7 @@ test_memcmp (void) int cnt = 1; char one[21]; char two[21]; - + it = "memcmp"; check(memcmp("a", "a", 1) == 0, cnt++); /* Identity. */ check(memcmp("abc", "abc", 3) == 0, cnt++); /* Multicharacter. */ -- cgit 1.4.1