diff options
author | dgp <dgp@users.sourceforge.net> | 2011-09-15 16:27:42 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2011-09-15 16:27:42 (GMT) |
commit | ef09f86d39a751b46143aa33f2ee808b31a6a984 (patch) | |
tree | 0246761d67f1f962dc31862f8e273843f53f3918 /generic | |
parent | da0b87b68ac41cf27cf21d098a19599b8e7059cd (diff) | |
download | tcl-ef09f86d39a751b46143aa33f2ee808b31a6a984.zip tcl-ef09f86d39a751b46143aa33f2ee808b31a6a984.tar.gz tcl-ef09f86d39a751b46143aa33f2ee808b31a6a984.tar.bz2 |
3408408 Partial improvement by sharing as literals the computed values of
constant subexpressions when we can do so without incurring the cost of
string rep generation.
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tclCompExpr.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/generic/tclCompExpr.c b/generic/tclCompExpr.c index 80f21e4..d96670c 100644 --- a/generic/tclCompExpr.c +++ b/generic/tclCompExpr.c @@ -2471,8 +2471,30 @@ CompileExprTree( if (ExecConstantExprTree(interp, nodes, next, litObjvPtr) == TCL_OK) { - TclEmitPush(TclAddLiteralObj(envPtr, - Tcl_GetObjResult(interp), NULL), envPtr); + int index; + Tcl_Obj *objPtr = Tcl_GetObjResult(interp); + + /* + * Don't generate a string rep, but if we have one + * already, then use it to share via the literal table. + */ + if (objPtr->bytes) { + Tcl_Obj *tableValue; + + index = TclRegisterNewLiteral(envPtr, objPtr->bytes, + objPtr->length); + tableValue = envPtr->literalArrayPtr[index].objPtr; + if ((tableValue->typePtr == NULL) && + (objPtr->typePtr != NULL)) { + /* Same intrep surgery as for OT_LITERAL */ + tableValue->typePtr = objPtr->typePtr; + tableValue->internalRep = objPtr->internalRep; + objPtr->typePtr = NULL; + } + } else { + index = TclAddLiteralObj(envPtr, objPtr, NULL); + } + TclEmitPush(index, envPtr); } else { TclCompileSyntaxError(interp, envPtr); } |