diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | string/strncpy.c | 14 |
2 files changed, 10 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog index 5e45a58779..4e557a7f22 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,8 @@ -2014-09-23 Wilco Dijkstra <wdijkstr@arm.com> +2014-11-24 Wilco Dijkstra <wdijkstr@arm.com> + + * string/strncpy.c (strncpy): Improve performance by using memset. + +2014-11-24 Wilco Dijkstra <wdijkstr@arm.com> * string/strcpy.c (strcpy): Improve performance by using strlen and memcpy. diff --git a/string/strncpy.c b/string/strncpy.c index 0915e036d6..d5fa5be08f 100644 --- a/string/strncpy.c +++ b/string/strncpy.c @@ -57,10 +57,10 @@ STRNCPY (char *s1, const char *s2, size_t n) if (--n4 == 0) goto last_chars; } - n = n - (s1 - s) - 1; - if (n == 0) - return s; - goto zero_fill; + s1++; + n = n - (s1 - s); + memset (s1, '\0', n); + return s; } last_chars: @@ -77,11 +77,7 @@ STRNCPY (char *s1, const char *s2, size_t n) } while (c != '\0'); - zero_fill: - do - *++s1 = '\0'; - while (--n > 0); - + memset (s1 + 1, '\0', n); return s; } libc_hidden_builtin_def (strncpy) |