optimise {}-appends
Closed / Accepted924097ffffffffffffffffffffffffffffffffffCreated 23 years agoUpdated 22 years ago
Descriptionplain2004-03-26 18:35:27
When appending to a Tcl_Obj, check first if the obj to
be appended is {}. In that case, return the untouched
original obj - avoid computing it's stringRep or
invalidating it's internalRep.
With this in place, the inline version of
K $x [set x {}]
can be written
$x[set x {}]
for greater performance.
Remark that this optimisation can be done at run time,
and also at compile time if the obj to be appended is
known to be {}. The compile time opt is however rather
involved - in the example above it would be possible in
principle (as 'set' is compiled, a redefinition will
trigger a recompilation of the whole script), but not in
$x[unset x]
dgpplain2004-03-27 02:06:48
Logged In: YES user_id=80530 the compiletime optimization is probably not possible, without some guarantee that there will not be a write trace on x at run time. (which might raise an error, or set a different, non-empty value).
dkfplain2004-03-29 17:40:18
Logged In: YES user_id=79902 Start by doing the runtime opt as that should be a safe peephole thing. Compile time optimisation is trickier because of the issues that DGP mentions, though I think there are ways round it. Those particular ideas of mine need more baking first though...
msoferplain2004-09-10 19:49:15
Logged In: YES user_id=148712 Peephole optimisation to INST_CONCAT1 commited.
Log in (anonymous is fine) to add a comment.