mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-27 11:43:34 +08:00
wcsmbs: optimize wcsnlen
This patch rewrites wcsnlen using wmemchr. The generic wmemchr already uses the strategy (loop unrolling and tail handling) and by using it it allows architectures that have optimized wmemchr (s390 and x86_64) to optimize wcsnlen as well. Checked on x86_64-linux-gnu. * wcsmbs/wcsnlen.c (__wcsnlen): Rewrite using wmemchr.
This commit is contained in:
parent
30a7e2081c
commit
457208b1e9
@ -1,5 +1,7 @@
|
||||
2019-02-27 Adhemerval Zanella <adhemerval.zanella@linaro.org>
|
||||
|
||||
* wcsmbs/wcsnlen.c (__wcsnlen): Rewrite using wmemchr.
|
||||
|
||||
* wcsmbs/wcsncpy.c (__wcsncpy): Rewrite using wcsnlen, wmemset, and
|
||||
wmemcpy.
|
||||
|
||||
|
@ -26,24 +26,10 @@
|
||||
size_t
|
||||
__wcsnlen (const wchar_t *s, size_t maxlen)
|
||||
{
|
||||
size_t len = 0;
|
||||
|
||||
while (maxlen > 0 && s[len] != L'\0')
|
||||
{
|
||||
++len;
|
||||
if (--maxlen == 0 || s[len] == L'\0')
|
||||
return len;
|
||||
++len;
|
||||
if (--maxlen == 0 || s[len] == L'\0')
|
||||
return len;
|
||||
++len;
|
||||
if (--maxlen == 0 || s[len] == L'\0')
|
||||
return len;
|
||||
++len;
|
||||
--maxlen;
|
||||
}
|
||||
|
||||
return len;
|
||||
const wchar_t *ret = __wmemchr (s, L'\0', maxlen);
|
||||
if (ret)
|
||||
maxlen = ret - s;
|
||||
return maxlen;
|
||||
}
|
||||
#ifndef WCSNLEN
|
||||
weak_alias (__wcsnlen, wcsnlen)
|
||||
|
Loading…
Reference in New Issue
Block a user