[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] Speed up tor_strndup a lot: profiling suggests that our use...
- To: or-cvs@freehaven.net
- Subject: [or-cvs] Speed up tor_strndup a lot: profiling suggests that our use...
- From: nickm@seul.org (Nick Mathewson)
- Date: Fri, 12 Nov 2004 15:41:06 -0500 (EST)
- Delivered-to: archiver@seul.org
- Delivered-to: or-cvs-outgoing@seul.org
- Delivered-to: or-cvs@seul.org
- Delivery-date: Fri, 12 Nov 2004 15:41:25 -0500
- Reply-to: or-dev@freehaven.net
- Sender: owner-or-cvs@freehaven.net
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;
}