diff options
author | dgp <dgp@users.sourceforge.net> | 2007-03-30 15:54:17 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2007-03-30 15:54:17 (GMT) |
commit | 693f3d9a86a49acd636864d887c910d7bdc34e7a (patch) | |
tree | 960312ad0c6ad40a3e28757dd61e040a7a402de7 /generic/tclCmdMZ.c | |
parent | be08ebe8c59b736ff0e850b7131987a32e799ee4 (diff) | |
download | tcl-693f3d9a86a49acd636864d887c910d7bdc34e7a.zip tcl-693f3d9a86a49acd636864d887c910d7bdc34e7a.tar.gz tcl-693f3d9a86a49acd636864d887c910d7bdc34e7a.tar.bz2 |
* generic/tclCmdMZ.c: Revised [string to* $s $first $last]
implementation to reduce number of allocs/copies.
Diffstat (limited to 'generic/tclCmdMZ.c')
-rw-r--r-- | generic/tclCmdMZ.c | 12 |
1 files changed, 4 insertions, 8 deletions
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; |