about summary refs log tree commit diff
path: root/wcsmbs
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2019-02-05 17:34:21 -0200
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2019-02-27 10:00:38 -0300
commit39ef07441910c2d2f8c02579e808862194b9a23b (patch)
tree34c8d7a478ab0ad6b8f106b0686a701e8ed355a9 /wcsmbs
parent7b3fb620519f6887b2650cc8e0e3267e44914c7b (diff)
downloadglibc-39ef07441910c2d2f8c02579e808862194b9a23b.tar.gz
glibc-39ef07441910c2d2f8c02579e808862194b9a23b.tar.xz
glibc-39ef07441910c2d2f8c02579e808862194b9a23b.zip
wcsmbs: optimize wcpncpy
This patch rewrites wcpncpy using wcslen, wmemcpy, and wmemset.  This is
similar to the optimization done on stpncpy by 48497aba8e.

Checked on x86_64-linux-gnu.

        * wcsmbs/wcpncpy.c (__wcpcpy): Rewrite using wcslen, wmemcpy, and
	wmemset.
Diffstat (limited to 'wcsmbs')
-rw-r--r--wcsmbs/wcpncpy.c57
1 files changed, 5 insertions, 52 deletions
diff --git a/wcsmbs/wcpncpy.c b/wcsmbs/wcpncpy.c
index 7568f3b11c..74f22c277c 100644
--- a/wcsmbs/wcpncpy.c
+++ b/wcsmbs/wcpncpy.c
@@ -27,59 +27,12 @@
 wchar_t *
 __wcpncpy (wchar_t *dest, const wchar_t *src, size_t n)
 {
-  wint_t c;
-  wchar_t *const s = 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 -= dest - s;
-      goto zero_fill;
-    }
-
- last_chars:
-  n &= 3;
-  if (n == 0)
+  size_t size = __wcsnlen (src, n);
+  __wmemcpy (dest, src, size);
+  dest += size;
+  if (size == n)
     return dest;
-
-  for (;;)
-    {
-      c = *src++;
-      --n;
-      *dest++ = c;
-      if (c == L'\0')
-	break;
-      if (n == 0)
-	return dest;
-    }
-
- zero_fill:
-  while (n-- > 0)
-    dest[n] = L'\0';
-
-  return dest - 1;
+  return wmemset (dest, L'\0', (n - size));
 }
 
 #ifndef WCPNCPY