diff options
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | generic/tclCmdMZ.c | 12 |
2 files changed, 7 insertions, 8 deletions
@@ -1,5 +1,8 @@ 2007-03-30 Don Porter <dgp@users.sourceforge.net> + * 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 <msofer@users.sf.net> 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; |