Ticket UUID: | 1194015 | |||
Title: | macro-ize TclFormatInt | |||
Type: | RFE | Version: | None | |
Submitter: | dgp | Created on: | 2005-05-02 19:47:35 | |
Subsystem: | 10. Objects | Assigned To: | dgp | |
Priority: | 5 Medium | Severity: | ||
Status: | Closed | Last Modified: | 2010-12-01 01:14:23 | |
Resolution: | Accepted | Closed By: | dgp | |
Closed on: | 2005-07-05 18:15:23 | |||
Description: |
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.) | |||
User Comments: |
hobbs added on 2010-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. dgp added on 2005-07-06 01:15:25: File Added - 140953: 1194015.patch dgp added on 2005-07-06 01:15:23: Logged In: YES user_id=80530 committing the attached patch to HEAD. jenglish added on 2005-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. |
Attachments:
- 1194015.patch [download] added by dgp on 2005-07-06 01:15:23. [details]