From 6796e0dc0d3d6ca82861853d28fa4af50eae73b4 Mon Sep 17 00:00:00 2001 From: dgp Date: Thu, 15 Sep 2005 16:58:24 +0000 Subject: * generic/tclStringObj.c (TclAppendFormattedObjs): Revision to eliminate one round of string copying. --- ChangeLog | 3 +++ generic/tclStringObj.c | 16 +++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index de3c6bf..73ab9b6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2005-09-15 Don Porter + * generic/tclStringObj.c (TclAppendFormattedObjs): Revision + to eliminate one round of string copying. + * generic/tclBasic.c: More callers of TclObjPrintf and * generic/tclCkalloc.c: TclFormatToErrorInfo. * generic/tclCmdMZ.c: diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c index d5aa6d8..d5dedc2 100644 --- a/generic/tclStringObj.c +++ b/generic/tclStringObj.c @@ -33,7 +33,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclStringObj.c,v 1.47 2005/09/14 21:32:17 dgp Exp $ */ + * RCS: @(#) $Id: tclStringObj.c,v 1.48 2005/09/15 16:58:24 dgp Exp $ */ #include "tclInt.h" @@ -1694,9 +1694,9 @@ Tcl_AppendStringsToObj(Tcl_Obj *objPtr, ...) */ int -TclAppendFormattedObjs(interp, baseObj, format, objc, objv) +TclAppendFormattedObjs(interp, appendObj, format, objc, objv) Tcl_Interp *interp; - Tcl_Obj *baseObj; + Tcl_Obj *appendObj; CONST char *format; int objc; Tcl_Obj *CONST objv[]; @@ -1705,7 +1705,7 @@ TclAppendFormattedObjs(interp, baseObj, format, objc, objv) int numBytes = 0; int objIndex = 0; int gotXpg = 0, gotSequential = 0; - Tcl_Obj *appendObj = Tcl_NewObj(); + int originalLength; CONST char *msg; CONST char *mixedXPG = "cannot mix \"%\" and \"%n$\" conversion specifiers"; CONST char *badIndex[2] = { @@ -1713,11 +1713,11 @@ TclAppendFormattedObjs(interp, baseObj, format, objc, objv) "\"%n$\" argument index out of range" }; - if (Tcl_IsShared(baseObj)) { + if (Tcl_IsShared(appendObj)) { Tcl_Panic("TclAppendFormattedObjs called with shared object"); } + Tcl_GetStringFromObj(appendObj, &originalLength); - Tcl_IncrRefCount(appendObj); /* format string is NUL-terminated */ while (*format != '\0') { char *end; @@ -2185,8 +2185,6 @@ TclAppendFormattedObjs(interp, baseObj, format, objc, objv) numBytes = 0; } - Tcl_AppendObjToObj(baseObj, appendObj); - Tcl_DecrRefCount(appendObj); return TCL_OK; errorMsg: @@ -2194,7 +2192,7 @@ TclAppendFormattedObjs(interp, baseObj, format, objc, objv) Tcl_SetObjResult(interp, Tcl_NewStringObj(msg, -1)); } error: - Tcl_DecrRefCount(appendObj); + Tcl_SetObjLength(appendObj, originalLength); return TCL_ERROR; } -- cgit v0.12