From 5425cd4eff7fc1e6305d9bd4c5b84510835ebc7c Mon Sep 17 00:00:00 2001 From: hobbs Date: Wed, 13 Dec 2000 19:44:15 +0000 Subject: * generic/tkObj.c (SetMMFromAny): Added ability to recognize double type object to speed up canvas coord calculations. [Patch #102471] --- ChangeLog | 6 ++++ generic/tkObj.c | 102 ++++++++++++++++++++++++++++++-------------------------- 2 files changed, 61 insertions(+), 47 deletions(-) diff --git a/ChangeLog b/ChangeLog index c3d87d6..26fc4c8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2000-12-13 jeff hobbs + + * generic/tkObj.c (SetMMFromAny): Added ability to recognize + double type object to speed up canvas coord calculations. + [Patch #102471] + 2000-12-12 Donal K. Fellows * doc/entry.n: Improved documentation of interplay between the 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; } -- cgit v0.12