aboutsummaryrefslogtreecommitdiff
path: root/wcsmbs/wcsncpy.c
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2019-02-05 18:48:31 -0200
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2019-02-27 10:00:37 -0300
commit30a7e2081c690dbb22022e1a7d276341b7391434 (patch)
treeed9c670f923dc70d0e8cfb26b8adb095d24b0cf9 /wcsmbs/wcsncpy.c
parentddf21ec79f25410bed8ab25de5a7d3003a8d03b8 (diff)
downloadglibc-30a7e2081c690dbb22022e1a7d276341b7391434.zip
glibc-30a7e2081c690dbb22022e1a7d276341b7391434.tar.gz
glibc-30a7e2081c690dbb22022e1a7d276341b7391434.tar.bz2
wcsmbs: optimize wcsncpy
This patch rewrites wcsncpy using wcsnlen, wmemset, and wmemcpy. This is similar to the optimization done on strncpy by f6482cf29d and 6423d4754c. Checked on x86_64-linux-gnu. * wcsmbs/wcsncpy.c (__wcsncpy): Rewrite using wcsnlen, wmemset, and wmemcpy.
Diffstat (limited to 'wcsmbs/wcsncpy.c')
-rw-r--r--wcsmbs/wcsncpy.c60
1 files changed, 4 insertions, 56 deletions
diff --git a/wcsmbs/wcsncpy.c b/wcsmbs/wcsncpy.c
index 2fd523c..d5d7f4a 100644
--- a/wcsmbs/wcsncpy.c
+++ b/wcsmbs/wcsncpy.c
@@ -26,62 +26,10 @@
wchar_t *
__wcsncpy (wchar_t *dest, const wchar_t *src, size_t n)
{
- wint_t c;
- wchar_t *const s = dest;
-
- --dest;
-
- if (n >= 4)
- {
- size_t n4 = n >> 2;
-
- for (;;)
- {
- c = *src++;
- *++dest = c;
- if (c == L'\0')
- break;
- c = *src++;
- *++dest = c;
- if (c == L'\0')
- break;
- c = *src++;
- *++dest = c;
- if (c == L'\0')
- break;
- c = *src++;
- *++dest = c;
- if (c == L'\0')
- break;
- if (--n4 == 0)
- goto last_chars;
- }
- n = n - (dest - s) - 1;
- if (n == 0)
- return s;
- goto zero_fill;
- }
-
- last_chars:
- n &= 3;
- if (n == 0)
- return s;
-
- do
- {
- c = *src++;
- *++dest = c;
- if (--n == 0)
- return s;
- }
- while (c != L'\0');
-
- zero_fill:
- do
- *++dest = L'\0';
- while (--n > 0);
-
- return s;
+ size_t size = __wcsnlen (src, n);
+ if (size != n)
+ __wmemset (dest + size, L'\0', n - size);
+ return __wmemcpy (dest, src, size);
}
#ifndef WCSNCPY
weak_alias (__wcsncpy, wcsncpy)