[or-cvs] Speed up tor_strndup a lot: profiling suggests that our use...

Nick Mathewson nickm at seul.org
Fri Nov 12 20:41:06 UTC 2004


Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/tmp/cvs-serv8480/src/common

Modified Files:
	util.c 
Log Message:
Speed up tor_strndup a lot: profiling suggests that our use of strlcpy here was a bad idea.

Index: util.c
===================================================================
RCS file: /home/or/cvsroot/src/common/util.c,v
retrieving revision 1.178
retrieving revision 1.179
diff -u -d -r1.178 -r1.179
--- util.c	12 Nov 2004 16:39:02 -0000	1.178
+++ util.c	12 Nov 2004 20:41:03 -0000	1.179
@@ -167,7 +167,12 @@
   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;
 }
 



More information about the tor-commits mailing list