summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2019-12-22 14:52:33 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2019-12-22 14:52:33 (GMT)
commit834ee2dd0d502b27a5bce4983910b0d05ff76aab (patch)
tree118cfebb53f88e8912dc3673a65b0c8f3ea499bb /generic
parentf3e5dd7a047e53790fe6316d5a5130dc5df80ef1 (diff)
downloadtcl-834ee2dd0d502b27a5bce4983910b0d05ff76aab.zip
tcl-834ee2dd0d502b27a5bce4983910b0d05ff76aab.tar.gz
tcl-834ee2dd0d502b27a5bce4983910b0d05ff76aab.tar.bz2
Minor optimization in TclFormatInt: No need to check for "0" as special value. No need to include final NULL-byte in character-reversion operation, as we already known the NULL-byte will come last.
Diffstat (limited to 'generic')
-rw-r--r--generic/tclUtil.c23
1 files changed, 5 insertions, 18 deletions
diff --git a/generic/tclUtil.c b/generic/tclUtil.c
index 96798bc..c972b8b 100644
--- a/generic/tclUtil.c
+++ b/generic/tclUtil.c
@@ -3598,37 +3598,24 @@ TclFormatInt(
long n) /* The integer to format. */
{
unsigned long intVal;
- int i;
+ int i = 0;
int numFormatted, j;
static const char digits[] = "0123456789";
/*
- * Check first whether "n" is zero.
- */
-
- if (n == 0) {
- buffer[0] = '0';
- buffer[1] = 0;
- return 1;
- }
-
- /*
* Generate the characters of the result backwards in the buffer.
*/
intVal = (n < 0 ? -(unsigned long)n : (unsigned long)n);
- i = 0;
- buffer[0] = '\0';
do {
- i++;
- buffer[i] = digits[intVal % 10];
+ buffer[i++] = digits[intVal % 10];
intVal = intVal / 10;
} while (intVal > 0);
if (n < 0) {
- i++;
- buffer[i] = '-';
+ buffer[i++] = '-';
}
- numFormatted = i;
+ buffer[i] = '\0';
+ numFormatted = i--;
/*
* Now reverse the characters.