summaryrefslogtreecommitdiffstats
path: root/generic/tclVar.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2016-07-20 16:32:16 (GMT)
committerdgp <dgp@users.sourceforge.net>2016-07-20 16:32:16 (GMT)
commit1eff5acecce7c6cae25d692ba941f02c9961dc74 (patch)
treea9cb731908fbf91ee21cbf5f35c1839d6e7ef831 /generic/tclVar.c
parentfcf66a8c31f5c02f6b8337c822d21e55c07df7f6 (diff)
downloadtcl-1eff5acecce7c6cae25d692ba941f02c9961dc74.zip
tcl-1eff5acecce7c6cae25d692ba941f02c9961dc74.tar.gz
tcl-1eff5acecce7c6cae25d692ba941f02c9961dc74.tar.bz2
Use strchr() to parse array variable syntax.
Diffstat (limited to 'generic/tclVar.c')
-rw-r--r--generic/tclVar.c58
1 files changed, 15 insertions, 43 deletions
diff --git a/generic/tclVar.c b/generic/tclVar.c
index 56c5a05..20fce82 100644
--- a/generic/tclVar.c
+++ b/generic/tclVar.c
@@ -504,9 +504,8 @@ TclObjLookupVarEx(
register Var *varPtr; /* Points to the variable's in-frame Var
* structure. */
const char *part1;
- int index, len1, len2;
+ int index, len;
int parsed = 0;
- Tcl_Obj *objPtr;
const Tcl_ObjType *typePtr = part1Ptr->typePtr;
const char *errMsg = NULL;
CallFrame *varFramePtr = iPtr->varFramePtr;
@@ -566,18 +565,17 @@ TclObjLookupVarEx(
}
parsed = 1;
}
- part1 = TclGetStringFromObj(part1Ptr, &len1);
+ part1 = TclGetStringFromObj(part1Ptr, &len);
- if (!parsed && len1 && (*(part1 + len1 - 1) == ')')) {
+ if (!parsed && len && (*(part1 + len - 1) == ')')) {
/*
* part1Ptr is possibly an unparsed array element.
*/
- register int i;
+ part2 = strchr(part1, '(');
+ if (part2) {
+ Tcl_Obj *arrayPtr;
- len2 = -1;
- for (i = 0; i < len1; i++) {
- if (*(part1 + i) == '(') {
if (part2Ptr != NULL) {
if (flags & TCL_LEAVE_ERR_MSG) {
TclObjVarErrMsg(interp, part1Ptr, part2Ptr, msg,
@@ -588,44 +586,18 @@ TclObjLookupVarEx(
return NULL;
}
- /*
- * part1Ptr points to an array element; first copy the element
- * name to a new string part2.
- */
-
- part2 = part1 + i + 1;
- len2 = len1 - i - 2;
- len1 = i;
-
- part2Ptr = Tcl_NewStringObj(part2, len2);
-
- /*
- * Free the internal rep of the original part1Ptr, now renamed
- * objPtr, and set it to tclParsedVarNameType.
- */
+ arrayPtr = Tcl_NewStringObj(part1, (part2 - part1));
+ part2Ptr = Tcl_NewStringObj(part2 + 1, len - (part2 - part1) - 2);
- objPtr = part1Ptr;
- TclFreeIntRep(objPtr);
- objPtr->typePtr = &tclParsedVarNameType;
+ TclFreeIntRep(part1Ptr);
- /*
- * Define a new string object to hold the new part1Ptr, i.e.,
- * the array name. Set the internal rep of objPtr, reset
- * typePtr and part1 to contain the references to the array
- * name.
- */
-
- TclNewStringObj(part1Ptr, part1, len1);
- Tcl_IncrRefCount(part1Ptr);
-
- objPtr->internalRep.twoPtrValue.ptr1 = part1Ptr;
- Tcl_IncrRefCount(part2Ptr);
- objPtr->internalRep.twoPtrValue.ptr2 = part2Ptr;
+ Tcl_IncrRefCount(arrayPtr);
+ part1Ptr->internalRep.twoPtrValue.ptr1 = arrayPtr;
+ Tcl_IncrRefCount(part2Ptr);
+ part1Ptr->internalRep.twoPtrValue.ptr2 = part2Ptr;
+ part1Ptr->typePtr = &tclParsedVarNameType;
- typePtr = part1Ptr->typePtr;
- part1 = TclGetString(part1Ptr);
- break;
- }
+ part1Ptr = arrayPtr;
}
}