diff options
author | Wilco Dijkstra <wdijkstr@arm.com> | 2014-11-24 15:15:10 +0000 |
---|---|---|
committer | Wilco Dijkstra <wdijkstr@arm.com> | 2014-11-24 15:15:10 +0000 |
commit | 6423d4754c3769129510b9b44b6b8cfe8192ec67 (patch) | |
tree | 2fa198519abedba525fc2f863fc817501f03e8e6 /string | |
parent | b863d2bc4db728213e54ff502d2c3ae5dfa0db25 (diff) | |
download | glibc-6423d4754c3769129510b9b44b6b8cfe8192ec67.zip glibc-6423d4754c3769129510b9b44b6b8cfe8192ec67.tar.gz glibc-6423d4754c3769129510b9b44b6b8cfe8192ec67.tar.bz2 |
Improve performance of strncpy.
Diffstat (limited to 'string')
-rw-r--r-- | string/strncpy.c | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/string/strncpy.c b/string/strncpy.c index 0915e03..d5fa5be 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) |