|
2025-09-08
| ||
| 14:20 | • Closed ticket [10545687da]: Improve Tcl_GetNumberFromObj with abstract list inte... artifact: 276a7abacc user: dgp | |
|
2025-09-07
| ||
| 10:15 | • Ticket [10545687da]: 3 changes artifact: 963863b4e4 user: jan.nijtmans | |
|
2025-09-06
| ||
| 10:32 | • Ticket [10545687da]: 3 changes artifact: e8df6e42fe user: jan.nijtmans | |
| 10:15 | • Ticket [10545687da]: 3 changes artifact: 4b6f9df217 user: jan.nijtmans | |
|
2025-09-05
| ||
| 19:58 | • Ticket [10545687da]: 3 changes artifact: 1c4db6a439 user: dgp | |
| 15:13 | • Ticket [10545687da]: 3 changes artifact: a76f7778a7 user: jan.nijtmans | |
| 13:52 | • Ticket [10545687da]: 3 changes artifact: a422c44717 user: griffin | |
| 13:44 | • Ticket [10545687da]: 3 changes artifact: 5920eddf8b user: dgp | |
| 13:05 | • Ticket [10545687da]: 3 changes artifact: be25ddce97 user: jan.nijtmans | |
| 13:01 | • Ticket [10545687da]: 3 changes artifact: 9ffc461106 user: jan.nijtmans | |
|
2025-09-04
| ||
| 19:12 | • Ticket [10545687da]: 3 changes artifact: 9d56d700b9 user: dgp | |
| 19:12 | [10545687da] Re-order efficiency shortcuts in Tcl_GetNumberFromObj(). check-in: f62f0e905f user: dgp tags: bug-10545687da | |
| 19:10 | • New ticket [10545687da] Improve Tcl_GetNumberFromObj with abstract list interfac... artifact: 6f7c202ff0 user: dgp | |
Improve Tcl_GetNumberFromObj with abstract list interfaces
Tcl_GetNumberFromObj() has already been written to make use of the extended Tcl_ObjType abstract list routines to efficiently reject non-singleton lists as non-numbers. I have a patch to re-order this processing, which is possible because all of Tcl's numeric types have implemented the abstract list routines so rejecting early is efficient enough to come first without worry about slowing down the accept results noticeably. Some comments are added to help later readers understand the logic.
f62f0e905f[10545687da] Re-order efficiency shortcuts in Tcl_GetNumberFromObj(). check-in2025-09-04 19:12:00
Branch bug-10545687da ready for review and merge.
Actually, I don't like this change.
What is done here is speed-up the error-case, slowing down the most-common OK case, where the Tcl_Obj is already a double, int or bignum.
It's only a few compare operations, not much at all, but I don't see much benefit on this change. Speed is more important for the OK case than for the error-case (which is already slow anyway), therefore I prefer the code as it was.
Sorry!
Adding comments, so people understand the logic is always good. Maybe we should comment here why checking for double/int/bignum is done first.
Another reason the lengthProc() shouldn't be called first: What if some extension implements an objtype which is implemented as a linked list. Then the lengthProc() of this type might be very costly. That's why lengthProc() should be called last, after all other (cheap) type checks.
I think if you reflect a little longer you will see that your second comment doesn't match how these facilities are used. I will look again to see what adaptations can take account of your first comment.
Not sure if making a choice based on potential bad actors implementing poorly designed abstract lists is wise. Then there's the coder that chooses to use GetNumber without having some reasonable assumption that it is a number. I think avoiding string creation whenever possible is as important as avoiding shimmering. What is needed is some test results that characterize the different approaches.
Note that there are 8 functions following the same concept: Tcl_GetNumberFromObj(), Tcl_GetLongFromObj(), Tcl_GetWideIntFromObj(), Tcl_GetWideUIntFromObj(), TclGetWideBitsFromObj(), GetBignumFromObj(), Tcl_GetDoubleFromObj() and Tcl_GetBoolFromObj().
All of them do this to prevent generating the string representation in as many situations as possible.
Revised code committed for further review. Now that you point out the other places dealing with similar tasks, I'll see whether there's a refactor opportunity.
Even better: why not move the lengthProc protection into TclParseNumber(). Then all callers of TclParseNumber() can benefit from it
Note that [this] ticket is where this all originate from
[this] is (starting) the refactoring I had in mind. Not finished yet (the same can be done in some more functions), but you can already review this part.
This has been overtaken by work on another ticket. Closing.