summaryrefslogtreecommitdiffstats
path: root/generic/tclCmdMZ.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2007-03-28 19:03:41 (GMT)
committerdgp <dgp@users.sourceforge.net>2007-03-28 19:03:41 (GMT)
commitf0dcf496f096fd97761a4392ff77c13f9eb49707 (patch)
tree5e6ea6dfc617bfe467971c624cb6c9218f9eb92c /generic/tclCmdMZ.c
parent2ef27f98192e8690ab3b297accafe52001b24014 (diff)
downloadtcl-f0dcf496f096fd97761a4392ff77c13f9eb49707.zip
tcl-f0dcf496f096fd97761a4392ff77c13f9eb49707.tar.gz
tcl-f0dcf496f096fd97761a4392ff77c13f9eb49707.tar.bz2
* generic/tclCmdMZ.c (STR_REVERSE): Implement the actual
[string reverse] command in terms of the new TclStringObjReverse() routine. * generic/tclInt.h (TclStringObjReverse): New internal routine * generic/tclStringObj.c (TclStringObjReverse): that implements the [string reverse] operation, making use of knowledge/surgery of the String intrep to minimize the number of allocs and copies needed to do the job.
Diffstat (limited to 'generic/tclCmdMZ.c')
-rw-r--r--generic/tclCmdMZ.c38
1 files changed, 2 insertions, 36 deletions
diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c
index 709c8cd..4d82870 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.145 2007/03/27 16:44:05 dgp Exp $
+ * RCS: @(#) $Id: tclCmdMZ.c,v 1.146 2007/03/28 19:03:42 dgp Exp $
*/
#include "tclInt.h"
@@ -2245,46 +2245,12 @@ Tcl_StringObjCmd(
break;
}
case STR_REVERSE: {
- Tcl_UniChar *ustring1;
- int i, j;
-
if (objc != 3) {
Tcl_WrongNumArgs(interp, 2, objv, "string");
return TCL_ERROR;
}
- ustring1 = Tcl_GetUnicodeFromObj(objv[2], &length1);
- if (Tcl_IsShared(objv[2])) {
- Tcl_UniChar *ustring2 = (Tcl_UniChar *)
- ckalloc(sizeof(Tcl_UniChar) * (unsigned)length1);
-
- for (i=0,j=length1-1 ; i<length1 ; i++,j--) {
- ustring2[j] = ustring1[i];
- }
- Tcl_SetObjResult(interp, Tcl_NewUnicodeObj(ustring2, length1));
- ckfree((char *) ustring2);
- } else {
- /*
- * The object is unshared, so we can do the swap in-place. This
- * avoids memory allocation, and so is faster.
- */
-
- for (i=0,j=length1-1 ; i<j ; i++,j--) {
- Tcl_UniChar tmp = ustring1[i];
- ustring1[i] = ustring1[j];
- ustring1[j] = tmp;
- }
-
- /*
- * Tricky. Must invalidate the string (utf-8) representation to
- * ensure that it is regenerated from the "unicode" internal rep.
- */
-
- if (objv[2]->bytes != NULL) {
- Tcl_InvalidateStringRep(objv[2]);
- }
- Tcl_SetObjResult(interp, objv[2]);
- }
+ Tcl_SetObjResult(interp, TclStringObjReverse(objv[2]));
break;
}
case STR_TOLOWER: