diff options
author | Nick Mathewson <nickm@torproject.org> | 2004-11-12 20:41:03 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2004-11-12 20:41:03 +0000 |
commit | c466b7e72f650104e1c54c34b57cb182675f41e4 (patch) | |
tree | 2a64f86e74363658f62f151b0bbd1b0eb66ee069 | |
parent | eabcf6618ea341afc20c4e5414f92f4e8d2c41db (diff) | |
download | tor-c466b7e72f650104e1c54c34b57cb182675f41e4.tar.gz tor-c466b7e72f650104e1c54c34b57cb182675f41e4.zip |
Speed up tor_strndup a lot: profiling suggests that our use of strlcpy here was a bad idea.
svn:r2821
-rw-r--r-- | src/common/util.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/common/util.c b/src/common/util.c index 16cc290a8e..ced770e577 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -167,7 +167,12 @@ char *tor_strndup(const char *s, size_t n) { char *dup; tor_assert(s); dup = tor_malloc(n+1); - strlcpy(dup, s, n+1); + /* Performance note: Ordinarly we prefer strlcpy to strncpy. But + * this function gets called a whole lot, and platform strncpy is + * much faster than strlcpy when strlen(s) is much longer than n. + */ + strncpy(dup, s, n+1); + dup[n]='\0'; return dup; } |