From 693f3d9a86a49acd636864d887c910d7bdc34e7a Mon Sep 17 00:00:00 2001 From: dgp Date: Fri, 30 Mar 2007 15:54:17 +0000 Subject: * generic/tclCmdMZ.c: Revised [string to* $s $first $last] implementation to reduce number of allocs/copies. --- ChangeLog | 3 +++ generic/tclCmdMZ.c | 12 ++++-------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0208fd7..b741156 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2007-03-30 Don Porter + * generic/tclCmdMZ.c: Revised [string to* $s $first $last] + implementation to reduce number of allocs/copies. + * tests/string.test: More [string reverse] tests. 2007-03-30 Miguel Sofer diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c index 4d82870..67659c1 100644 --- a/generic/tclCmdMZ.c +++ b/generic/tclCmdMZ.c @@ -15,7 +15,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclCmdMZ.c,v 1.146 2007/03/28 19:03:42 dgp Exp $ + * RCS: @(#) $Id: tclCmdMZ.c,v 1.147 2007/03/30 15:54:17 dgp Exp $ */ #include "tclInt.h" @@ -2303,10 +2303,8 @@ Tcl_StringObjCmd( start = Tcl_UtfAtIndex(string1, first); end = Tcl_UtfAtIndex(start, last - first + 1); - length2 = end-start; - string2 = ckalloc((size_t) length2+1); - memcpy(string2, start, (size_t) length2); - string2[length2] = '\0'; + resultPtr = Tcl_NewStringObj(string1, end - string1); + string2 = Tcl_GetString(resultPtr) + (start - string1); if ((enum options) index == STR_TOLOWER) { length2 = Tcl_UtfToLower(string2); @@ -2315,12 +2313,10 @@ Tcl_StringObjCmd( } else { length2 = Tcl_UtfToTitle(string2); } + Tcl_SetObjLength(resultPtr, length2 + (start - string1)); - resultPtr = Tcl_NewStringObj(string1, start - string1); - Tcl_AppendToObj(resultPtr, string2, length2); Tcl_AppendToObj(resultPtr, end, -1); Tcl_SetObjResult(interp, resultPtr); - ckfree(string2); } break; -- cgit v0.12