summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2007-03-30 15:54:17 (GMT)
committerdgp <dgp@users.sourceforge.net>2007-03-30 15:54:17 (GMT)
commit693f3d9a86a49acd636864d887c910d7bdc34e7a (patch)
tree960312ad0c6ad40a3e28757dd61e040a7a402de7
parentbe08ebe8c59b736ff0e850b7131987a32e799ee4 (diff)
downloadtcl-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.
-rw-r--r--ChangeLog3
-rw-r--r--generic/tclCmdMZ.c12
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 <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;