Overview
| Artifact ID: | 46c8ff16b80fc2144fecf0a63a1d5dadfae3c6bf |
|---|---|
| Ticket: | 575194ffffffffffffffffffffffffffffffffff
Wasteful code in compile |
| User & Date: | pspjuth on 2002-06-28 20:56:25 |
Changes
- assignee changed to: "msofer"
- cmimetype changed to: "text/plain"
- comment changed to:
In compile code (e.g. tclCompCmds.c) the combo TclEmitPush and TclRegisterLiteral is rather common. Typically: TclEmitPush(TclRegisterLiteral(envPtr, valueTokenPtr[1].start, valueTokenPtr[1].size, /*onHeap*/ 0), envPtr); However, TclEmitPush is a macro which uses its first argument eight times and passes it at least three times, which makes the above statement rather wasteful. This is normally not any danger since TclRegisterLiteral can be called repeatedly without anything changing, if onHeap is 0 which is the normal case. With onHeap = 1, it becomes disaster since the successive calls deallocates the string. A naughty trap for an innocent coder who likes to copy code nearby :-) So, either a big warning sign should be placed on TclEmitPush and every use of the combo should be rewritten so the literal index is stored in a var first: objIndex = TclRegisterLiteral(envPtr, valueTokenPtr[1].start, valueTokenPtr[1].size, /*onHeap*/ 0); TclEmitPush(objIndex, envPtr); or, maybe TclEmitPush can be recoded to something better, like a function or e.g.: #define TclEmitPush(objIndex, envPtr) \ { register int __objIndex__ = (objIndex); \ if ((__objIndex__) <= 255) { \ TclEmitInstInt1(INST_PUSH1, (__objIndex__),\ (envPtr)); \ } else { \ TclEmitInstInt4(INST_PUSH4, (__objIndex__),\ (envPtr)); \ } \ } - foundin changed to: "None"
- priority changed to: "5 Medium"
- resolution changed to: "None"
- status changed to: "Open"
- submitter changed to: "pspjuth"
- subsystem changed to: "47. Bytecode Compiler"
- title changed to: "Wasteful code in compile"
- type changed to: "Bug"