Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2010-12-01
01:14 • Ticket [1194015fff] macro-ize TclFormatInt status still Closed with 4 other ... artifact: 89de8b4c46 user: hobbs
2005-07-06
01:15 • Ticket [1194015fff]: 4 changes artifact: 7e4504917a user: dgp
01:15 • Closed ticket [1194015fff]. artifact: acc981a69e user: dgp
01:15 • Add attachment 1194015.patch to ticket [1194015fff] artifact: 2cb2ce7869 user: dgp
2005-05-04
04:51 • Ticket [1194015fff] macro-ize TclFormatInt status still Open with 4 other ch... artifact: 43ba2f6125 user: jenglish
2005-05-02
19:47 • New ticket [1194015fff]. artifact: f9d61e179a user: dgp

macro-ize TclFormatInt

Closed / Accepted1194015fffffffffffffffffffffffffffffffffCreated 22 years agoUpdated 16 years ago
Descriptionplain2005-05-02 19:47:35
Given

  char *buf;
  long l;

it appears that

TclFormatInt(buf, l);

is the equivalent of

sprintf(buf, "%ld", l);

Therefore, I request to make
TclFormatInt a macro, #define'd
in tclInt.h :

  #define TclFormatInt(buf, l)  sprintf((buf), "%ld", (l))

Some compatibility provisions can be
made for the internal stubs table slot
currently occupied by the TclFormatInt
routine.

The comments of TclFormatInt allege:

 *      ...This
 *      procedure has the effect of sprintf(buffer,
"%d", n) but is faster.

Frankly, I don't believe that.  (Even ignoring the
"d" for "ld" error.)
jenglishplain2005-05-04 04:51:44
Logged In: YES 
user_id=68433

One possible problem area:  because of the function
prototype, at any call sites that currently pass an 'int' as
the second parameter it will be silently promoted to 'long';
if TclFormatInt() is replaced with a macro this will no
longer happen.

Also: this would introduce another dependency on <stdio.h>.
 This probably isn't a big deal since <tcl.h> already
#includes it and there are a bunch of other dependencies
already.
dgpplain2005-07-06 01:15:23
Logged In: YES 
user_id=80530


committing the attached patch
to HEAD.
dgpplain2005-07-06 01:15:25
File Added - 140953: 1194015.patch
hobbsplain2010-12-01 01:14:23
Just to note this change was reverted for 8.6 and 8.5.10 on 2010-11-30 after benchmarks proved TclFormatInt to be faster.  This is key to Tcl's int->string conversions, and the win is likely primarily in sprintf not needing to parse the "%ld" format.
Log in (anonymous is fine) to add a comment.

Attachments: