mirror of
https://sourceware.org/git/glibc.git
synced 2025-08-13 03:22:30 +03:00
wcsmbs: optimize wcsncat
This patch rewrites wcsncat using wcslen, wcsnlen, and wmemcpy. This is similar to the optimization done on strncat by3eb38795db
ande80514b5a8
. Checked on x86_64-linux-gnu. * wcsmbs/wcsncat.c (wcsncat): Rewrite using wcslen, wcsnlen, and wmemcpy.
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
2019-02-27 Adhemerval Zanella <adhemerval.zanella@linaro.org>
|
2019-02-27 Adhemerval Zanella <adhemerval.zanella@linaro.org>
|
||||||
|
|
||||||
|
* wcsmbs/wcsncat.c (wcsncat): Rewrite using wcslen, wcsnlen, and
|
||||||
|
wmemcpy.
|
||||||
|
|
||||||
* wcsmbs/wcscpy.c (__wcpcpy): Rewrite using wcslen and wmemcpy.
|
* wcsmbs/wcscpy.c (__wcpcpy): Rewrite using wcslen and wmemcpy.
|
||||||
|
|
||||||
* include/wchar.h (__wcscpy): New prototype.
|
* include/wchar.h (__wcscpy): New prototype.
|
||||||
|
@@ -26,54 +26,15 @@
|
|||||||
wchar_t *
|
wchar_t *
|
||||||
WCSNCAT (wchar_t *dest, const wchar_t *src, size_t n)
|
WCSNCAT (wchar_t *dest, const wchar_t *src, size_t n)
|
||||||
{
|
{
|
||||||
wchar_t c;
|
wchar_t *ret = dest;
|
||||||
wchar_t * const s = dest;
|
|
||||||
|
|
||||||
/* Find the end of DEST. */
|
/* Find the end of dest. */
|
||||||
do
|
dest += __wcslen (dest);
|
||||||
c = *dest++;
|
|
||||||
while (c != L'\0');
|
|
||||||
|
|
||||||
/* Make DEST point before next character, so we can increment
|
size_t ds = __wcsnlen (src, n);
|
||||||
it while memory is read (wins on pipelined cpus). */
|
|
||||||
dest -= 2;
|
|
||||||
|
|
||||||
if (n >= 4)
|
dest[ds] = L'\0';
|
||||||
{
|
__wmemcpy (dest, src, ds);
|
||||||
size_t n4 = n >> 2;
|
|
||||||
do
|
return ret;
|
||||||
{
|
|
||||||
c = *src++;
|
|
||||||
*++dest = c;
|
|
||||||
if (c == L'\0')
|
|
||||||
return s;
|
|
||||||
c = *src++;
|
|
||||||
*++dest = c;
|
|
||||||
if (c == L'\0')
|
|
||||||
return s;
|
|
||||||
c = *src++;
|
|
||||||
*++dest = c;
|
|
||||||
if (c == L'\0')
|
|
||||||
return s;
|
|
||||||
c = *src++;
|
|
||||||
*++dest = c;
|
|
||||||
if (c == L'\0')
|
|
||||||
return s;
|
|
||||||
} while (--n4 > 0);
|
|
||||||
n &= 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (n > 0)
|
|
||||||
{
|
|
||||||
c = *src++;
|
|
||||||
*++dest = c;
|
|
||||||
if (c == L'\0')
|
|
||||||
return s;
|
|
||||||
n--;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c != L'\0')
|
|
||||||
*++dest = L'\0';
|
|
||||||
|
|
||||||
return s;
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user