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:
Adhemerval Zanella 2019-02-05 18:55:59 -02:00
parent 30a7e2081c
commit 457208b1e9
2 changed files with 6 additions and 18 deletions

View File

@ -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.

View File

@ -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)