diff options
author | stanton <stanton> | 1999-05-04 02:57:54 (GMT) |
---|---|---|
committer | stanton <stanton> | 1999-05-04 02:57:54 (GMT) |
commit | ba038ecba199445b2f74cf0834ce258822ce5d6e (patch) | |
tree | f2e0f73961f829cecf16c8a2dc6fe78ef3006e70 /generic/tclCmdMZ.c | |
parent | f46a13245d6ed0be5a1de0604321ad773c4ec606 (diff) | |
download | tcl-ba038ecba199445b2f74cf0834ce258822ce5d6e.zip tcl-ba038ecba199445b2f74cf0834ce258822ce5d6e.tar.gz tcl-ba038ecba199445b2f74cf0834ce258822ce5d6e.tar.bz2 |
* doc/string.n:
* tests/cmdMZ.test:
* tests/string.test:
* generic/tclCmdMZ.c (Tcl_StringObjCmd): Changed "string length"
to avoid regenerating the string rep of a ByteArray object.
Diffstat (limited to 'generic/tclCmdMZ.c')
-rw-r--r-- | generic/tclCmdMZ.c | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c index 52cdf10..90b9687 100644 --- a/generic/tclCmdMZ.c +++ b/generic/tclCmdMZ.c @@ -13,7 +13,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.4 1999/05/04 01:33:10 stanton Exp $ + * RCS: @(#) $Id: tclCmdMZ.c,v 1.5 1999/05/04 02:57:55 stanton Exp $ */ #include "tclInt.h" @@ -806,7 +806,7 @@ Tcl_StringObjCmd(dummy, interp, objc, objv) char *string1, *string2; int length1, length2; static char *options[] = { - "bytes", "compare", "equal", "first", + "bytelength", "compare", "equal", "first", "icompare", "iequal", "index", "last", "length", "map", "match", "range", "repeat", "replace", @@ -815,7 +815,7 @@ Tcl_StringObjCmd(dummy, interp, objc, objv) "wordend", "wordstart", (char *) NULL }; enum options { - STR_BYTES, STR_COMPARE, STR_EQUAL, STR_FIRST, + STR_BYTELENGTH, STR_COMPARE, STR_EQUAL, STR_FIRST, STR_ICOMPARE, STR_IEQUAL, STR_INDEX, STR_LAST, STR_LENGTH, STR_MAP, STR_MATCH, STR_RANGE, STR_REPEAT, STR_REPLACE, @@ -1044,18 +1044,31 @@ Tcl_StringObjCmd(dummy, interp, objc, objv) Tcl_SetIntObj(resultPtr, match); break; } - case STR_BYTES: + case STR_BYTELENGTH: case STR_LENGTH: { if (objc != 3) { Tcl_WrongNumArgs(interp, 2, objv, "string"); return TCL_ERROR; } - string1 = Tcl_GetStringFromObj(objv[2], &length1); - if ((enum options) index == STR_BYTES) { + if ((enum options) index == STR_BYTELENGTH) { + string1 = Tcl_GetStringFromObj(objv[2], &length1); Tcl_SetIntObj(resultPtr, length1); } else { - Tcl_SetIntObj(resultPtr, Tcl_NumUtfChars(string1, length1)); + /* + * If we have a ByteArray object, avoid recomputing the + * string since the byte array contains one byte per + * character. + */ + + if (objv[2]->typePtr == &tclByteArrayType) { + string1 = Tcl_GetByteArrayFromObj(objv[2], &length1); + Tcl_SetIntObj(resultPtr, length1); + } else { + string1 = Tcl_GetStringFromObj(objv[2], &length1); + Tcl_SetIntObj(resultPtr, Tcl_NumUtfChars(string1, + length1)); + } } break; } |