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:
- 1194015.patch [download] added by dgp on 2005-07-06 01:15:23. [details]