summaryrefslogtreecommitdiffstats
path: root/lib/libc
diff options
context:
space:
mode:
authortjr <tjr@FreeBSD.org>2002-10-23 10:52:04 +0000
committertjr <tjr@FreeBSD.org>2002-10-23 10:52:04 +0000
commit416f05a258cd6f5a748ac6e3e427db176693989f (patch)
tree8c3b9bfca79a5f469d8b498a689ee36b22af39bc /lib/libc
parentf0735aa8f5cba3f083ed71230c6ebe4928b9bb58 (diff)
downloadFreeBSD-src-416f05a258cd6f5a748ac6e3e427db176693989f.zip
FreeBSD-src-416f05a258cd6f5a748ac6e3e427db176693989f.tar.gz
Reimplement more efficiently, using a single forward scan (like strrchr(3))
instead of scanning forwards to find the end of the string then scanning backwards to find the character.
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/string/wcsrchr.c34
1 files changed, 12 insertions, 22 deletions
diff --git a/lib/libc/string/wcsrchr.c b/lib/libc/string/wcsrchr.c
index 9294b8d..37c81ec 100644
--- a/lib/libc/string/wcsrchr.c
+++ b/lib/libc/string/wcsrchr.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c)1999 Citrus Project,
+ * Copyright (c) 2002 Tim J. Robbins
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -22,36 +22,26 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
- * citrus Id: wcsrchr.c,v 1.2 2000/12/21 05:07:25 itojun Exp
*/
#include <sys/cdefs.h>
-#if 0
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: wcsrchr.c,v 1.1 2000/12/23 23:14:37 itojun Exp $");
-#endif /* LIBC_SCCS and not lint */
-#endif
__FBSDID("$FreeBSD$");
#include <wchar.h>
wchar_t *
-wcsrchr(s, c)
- const wchar_t *s;
- wchar_t c;
+wcsrchr(const wchar_t *s, wchar_t c)
{
- const wchar_t *p;
+ const wchar_t *last;
- p = s;
- while (*p)
- p++;
- while (s <= p) {
- if (*p == c) {
- /* LINTED interface specification */
- return (wchar_t *)p;
- }
- p--;
+ last = NULL;
+ for (;;) {
+ if (*s == c)
+ last = s;
+ if (*s == L'\0')
+ break;
+ s++;
}
- return NULL;
+
+ return ((wchar_t *)last);
}
OpenPOWER on IntegriCloud