]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Speed up tor_strndup a lot: profiling suggests that our use of strlcpy here was a...
authorNick Mathewson <nickm@torproject.org>
Fri, 12 Nov 2004 20:41:03 +0000 (20:41 +0000)
committerNick Mathewson <nickm@torproject.org>
Fri, 12 Nov 2004 20:41:03 +0000 (20:41 +0000)
svn:r2821

src/common/util.c

index 16cc290a8e0f2e6c907d5b0c660fa2ed4fdf8bfb..ced770e57794432b3d390d3184f24ab82677bdb7 100644 (file)
@@ -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;
 }