This is the mail archive of the glibc-cvs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

GNU C Library master sources branch master updated. glibc-2.22-100-g48497ab


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, master has been updated
       via  48497aba8ec7887dd505e37aa95ab52348fa8cb2 (commit)
      from  a08e80d1143f6b0386d5bc8cc7b8ed576091dbf3 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=48497aba8ec7887dd505e37aa95ab52348fa8cb2

commit 48497aba8ec7887dd505e37aa95ab52348fa8cb2
Author: Wilco Dijkstra <wdijkstr@arm.com>
Date:   Wed Aug 19 16:28:21 2015 +0100

    Improve stpncpy performance by using __strnlen/memcpy/memset rather than a
    byte loop. Performance on bench-stpncpy is ~2x faster on average.

diff --git a/ChangeLog b/ChangeLog
index da4f3c7..2376021 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2015-08-19  Wilco Dijkstra  <wdijkstr@arm.com>
+
+	* string/stpncpy.c (stpncpy): Improve performance using
+	__strnlen/memcpy/memset.
+
 2015-08-19  Andrew Senkevich  <andrew.senkevich@intel.com>
 
 	[BZ #18796]
diff --git a/string/stpncpy.c b/string/stpncpy.c
index eb65a5f..4c3351b 100644
--- a/string/stpncpy.c
+++ b/string/stpncpy.c
@@ -15,8 +15,6 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-/* This is almost copied from strncpy.c, written by Torbjorn Granlund.  */
-
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
@@ -41,59 +39,12 @@ weak_alias (__stpncpy, stpncpy)
 char *
 STPNCPY (char *dest, const char *src, size_t n)
 {
-  char c;
-  char *s = dest;
-
-  if (n >= 4)
-    {
-      size_t n4 = n >> 2;
-
-      for (;;)
-	{
-	  c = *src++;
-	  *dest++ = c;
-	  if (c == '\0')
-	    break;
-	  c = *src++;
-	  *dest++ = c;
-	  if (c == '\0')
-	    break;
-	  c = *src++;
-	  *dest++ = c;
-	  if (c == '\0')
-	    break;
-	  c = *src++;
-	  *dest++ = c;
-	  if (c == '\0')
-	    break;
-	  if (--n4 == 0)
-	    goto last_chars;
-	}
-      n -= dest - s;
-      goto zero_fill;
-    }
-
- last_chars:
-  n &= 3;
-  if (n == 0)
+  size_t size = __strnlen (src, n);
+  memcpy (dest, src, size);
+  dest += size;
+  if (size == n)
     return dest;
-
-  for (;;)
-    {
-      c = *src++;
-      --n;
-      *dest++ = c;
-      if (c == '\0')
-	break;
-      if (n == 0)
-	return dest;
-    }
-
- zero_fill:
-  while (n-- > 0)
-    dest[n] = '\0';
-
-  return dest - 1;
+  return memset (dest, '\0', n - size);
 }
 #ifdef weak_alias
 libc_hidden_def (__stpncpy)

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog        |    5 ++++
 string/stpncpy.c |   59 ++++-------------------------------------------------
 2 files changed, 10 insertions(+), 54 deletions(-)


hooks/post-receive
-- 
GNU C Library master sources


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]