summaryrefslogtreecommitdiff
path: root/usr.bin/cvs
diff options
context:
space:
mode:
authorNiall O'Higgins <niallo@cvs.openbsd.org>2005-12-27 16:08:27 +0000
committerNiall O'Higgins <niallo@cvs.openbsd.org>2005-12-27 16:08:27 +0000
commit51ed52f34fc32f925fda9d391d9dc46c9c6c21a2 (patch)
tree7df8cf4a3927d722c719210faf72b9fd3aeeff85 /usr.bin/cvs
parente4827a10efc4c9779a532fdab3cfaf618c7f2ede (diff)
- optimise rcsnum_tostr(). we call this function a LOT and using multiple
snprintf()s in it is SLOW. second of a few important performance improvements. ok joris@
Diffstat (limited to 'usr.bin/cvs')
-rw-r--r--usr.bin/cvs/rcsnum.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/usr.bin/cvs/rcsnum.c b/usr.bin/cvs/rcsnum.c
index 41cdfc28f64..a7b3c841b47 100644
--- a/usr.bin/cvs/rcsnum.c
+++ b/usr.bin/cvs/rcsnum.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcsnum.c,v 1.19 2005/12/12 17:47:03 joris Exp $ */
+/* $OpenBSD: rcsnum.c,v 1.20 2005/12/27 16:08:26 niallo Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -37,6 +37,7 @@
static int rcsnum_setsize(RCSNUM *, u_int);
+static char *rcsnum_itoa(u_int16_t, char *, size_t);
/*
@@ -111,15 +112,32 @@ rcsnum_tostr(const RCSNUM *nump, char *buf, size_t blen)
return (buf);
}
- snprintf(buf, blen, "%u", nump->rn_id[0]);
+ strlcpy(buf, rcsnum_itoa(nump->rn_id[0], buf, blen), blen);
for (i = 1; i < nump->rn_len; i++) {
- snprintf(tmp, sizeof(tmp), ".%u", nump->rn_id[i]);
- strlcat(buf, tmp, blen);
+ strlcat(buf, ".", blen);
+ strlcat(buf, rcsnum_itoa(nump->rn_id[i], tmp, sizeof(tmp)),
+ blen);
}
return (buf);
}
+static char *
+rcsnum_itoa(u_int16_t num, char *buf, size_t len)
+{
+ u_int16_t i;
+ char *p;
+
+ p = buf + len - 1;
+ i = num;
+ bzero(buf, len);
+ while (i) {
+ *--p = '0' + (i % 10);
+ i /= 10;
+ }
+ return (p);
+}
+
/*
* rcsnum_cpy()
*