summaryrefslogtreecommitdiffstats
path: root/generic/tkObj.c
diff options
context:
space:
mode:
authorhobbs <hobbs>2000-12-13 19:44:15 (GMT)
committerhobbs <hobbs>2000-12-13 19:44:15 (GMT)
commit5425cd4eff7fc1e6305d9bd4c5b84510835ebc7c (patch)
treed2f48b116a56d241267cb96c9653c793050dd689 /generic/tkObj.c
parent61f5a94b7673b289a14c12d8b65d90dc57b0ed9d (diff)
downloadtk-5425cd4eff7fc1e6305d9bd4c5b84510835ebc7c.zip
tk-5425cd4eff7fc1e6305d9bd4c5b84510835ebc7c.tar.gz
tk-5425cd4eff7fc1e6305d9bd4c5b84510835ebc7c.tar.bz2
* generic/tkObj.c (SetMMFromAny): Added ability to recognize
double type object to speed up canvas coord calculations. [Patch #102471]
Diffstat (limited to 'generic/tkObj.c')
-rw-r--r--generic/tkObj.c102
1 files changed, 55 insertions, 47 deletions
diff --git a/generic/tkObj.c b/generic/tkObj.c
index ff2684c..e27bd4f 100644
--- a/generic/tkObj.c
+++ b/generic/tkObj.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkObj.c,v 1.2 1999/04/16 01:51:20 stanton Exp $
+ * RCS: @(#) $Id: tkObj.c,v 1.3 2000/12/13 19:44:15 hobbs Exp $
*/
#include "tkInt.h"
@@ -501,46 +501,52 @@ SetMMFromAny(interp, objPtr)
int units;
MMRep *mmPtr;
- string = Tcl_GetStringFromObj(objPtr, NULL);
-
- d = strtod(string, &rest);
- if (rest == string) {
- /*
- * Must copy string before resetting the result in case a caller
- * is trying to convert the interpreter's result to mms.
- */
-
- error:
- Tcl_AppendResult(interp, "bad screen distance \"", string,
- "\"", (char *) NULL);
- return TCL_ERROR;
- }
- while ((*rest != '\0') && isspace(UCHAR(*rest))) {
- rest++;
- }
- switch (*rest) {
- case '\0':
- units = -1;
- break;
-
- case 'c':
- units = 0;
- break;
-
- case 'i':
- units = 1;
- break;
-
- case 'm':
- units = 2;
- break;
-
- case 'p':
- units = 3;
- break;
-
- default:
- goto error;
+ if (objPtr->typePtr == &tclDoubleType) {
+ /* optimize for speed reasons */
+ Tcl_GetDoubleFromObj(interp, objPtr, &d);
+ units = -1;
+ } else {
+ string = Tcl_GetStringFromObj(objPtr, NULL);
+
+ d = strtod(string, &rest);
+ if (rest == string) {
+ /*
+ * Must copy string before resetting the result in case a caller
+ * is trying to convert the interpreter's result to mms.
+ */
+
+ error:
+ Tcl_AppendResult(interp, "bad screen distance \"", string,
+ "\"", (char *) NULL);
+ return TCL_ERROR;
+ }
+ while ((*rest != '\0') && isspace(UCHAR(*rest))) {
+ rest++;
+ }
+ switch (*rest) {
+ case '\0':
+ units = -1;
+ break;
+
+ case 'c':
+ units = 0;
+ break;
+
+ case 'i':
+ units = 1;
+ break;
+
+ case 'm':
+ units = 2;
+ break;
+
+ case 'p':
+ units = 3;
+ break;
+
+ default:
+ goto error;
+ }
}
/*
@@ -552,14 +558,16 @@ SetMMFromAny(interp, objPtr)
(*typePtr->freeIntRepProc)(objPtr);
}
- objPtr->typePtr = &mmObjType;
+ objPtr->typePtr = &mmObjType;
+
+ mmPtr = (MMRep *) ckalloc(sizeof(MMRep));
+ mmPtr->value = d;
+ mmPtr->units = units;
+ mmPtr->tkwin = NULL;
+ mmPtr->returnValue = d;
- mmPtr = (MMRep *) ckalloc(sizeof(MMRep));
- mmPtr->value = d;
- mmPtr->units = units;
- mmPtr->tkwin = NULL;
- mmPtr->returnValue = d;
objPtr->internalRep.otherValuePtr = (VOID *) mmPtr;
+
return TCL_OK;
}