summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2011-11-02 09:31:08 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2011-11-02 09:31:08 (GMT)
commit91ee5ad3a7b2ca1588901a5f8542f02a96a91cf1 (patch)
tree88fa3b5b07aa9c3a2c550371dedd635ab8a0f332 /generic
parent64cbf2d40cb1144be543df22dbc1a23abaaff8d2 (diff)
parent4425617a46ed8ed66c18049cf2514547a8b2290d (diff)
downloadtk-91ee5ad3a7b2ca1588901a5f8542f02a96a91cf1.zip
tk-91ee5ad3a7b2ca1588901a5f8542f02a96a91cf1.tar.gz
tk-91ee5ad3a7b2ca1588901a5f8542f02a96a91cf1.tar.bz2
A better way of managing the type cache across the tkObj.c file.
Diffstat (limited to 'generic')
-rw-r--r--generic/tkObj.c56
1 files changed, 32 insertions, 24 deletions
diff --git a/generic/tkObj.c b/generic/tkObj.c
index b287e2f..7affac4 100644
--- a/generic/tkObj.c
+++ b/generic/tkObj.c
@@ -87,6 +87,7 @@ static void DupWindowInternalRep(Tcl_Obj *srcPtr,Tcl_Obj*copyPtr);
static void FreeMMInternalRep(Tcl_Obj *objPtr);
static void FreePixelInternalRep(Tcl_Obj *objPtr);
static void FreeWindowInternalRep(Tcl_Obj *objPtr);
+static ThreadSpecificData *GetTypeCache(void);
static void UpdateStringOfMM(Tcl_Obj *objPtr);
static int SetMMFromAny(Tcl_Interp *interp, Tcl_Obj *objPtr);
static int SetPixelFromAny(Tcl_Interp *interp, Tcl_Obj *objPtr);
@@ -136,6 +137,31 @@ static const Tcl_ObjType windowObjType = {
/*
*----------------------------------------------------------------------
*
+ * GetTypeCache --
+ *
+ * Get (and build if necessary) the cache of useful Tcl object types for
+ * comparisons in the conversion functions. This allows optimized checks
+ * for standard cases.
+ *
+ *----------------------------------------------------------------------
+ */
+
+static ThreadSpecificData *
+GetTypeCache(void)
+{
+ ThreadSpecificData *tsdPtr =
+ Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
+
+ if (tsdPtr->doubleTypePtr == NULL) {
+ tsdPtr->doubleTypePtr = Tcl_GetObjType("double");
+ tsdPtr->intTypePtr = Tcl_GetObjType("int");
+ }
+ return tsdPtr;
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
* GetPixelsFromObjEx --
*
* Attempt to return a pixel value from the Tcl object "objPtr". If the
@@ -178,22 +204,16 @@ GetPixelsFromObjEx(
*/
if (objPtr->typePtr != &pixelObjType) {
- ThreadSpecificData *tsdPtr =
- Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
+ ThreadSpecificData *typeCache = GetTypeCache();
- if (tsdPtr->doubleTypePtr == NULL) {
- tsdPtr->doubleTypePtr = Tcl_GetObjType("double");
- tsdPtr->intTypePtr = Tcl_GetObjType("int");
- }
-
- if (objPtr->typePtr == tsdPtr->doubleTypePtr) {
+ if (objPtr->typePtr == typeCache->doubleTypePtr) {
(void) Tcl_GetDoubleFromObj(interp, objPtr, &d);
if (dblPtr != NULL) {
*dblPtr = d;
}
*intPtr = (int) d;
return TCL_OK;
- } else if (objPtr->typePtr == tsdPtr->intTypePtr) {
+ } else if (objPtr->typePtr == typeCache->intTypePtr) {
(void) Tcl_GetIntFromObj(interp, objPtr, intPtr);
if (dblPtr) {
*dblPtr = (double) (*intPtr);
@@ -681,6 +701,7 @@ SetMMFromAny(
Tcl_Interp *interp, /* Used for error reporting if not NULL. */
Tcl_Obj *objPtr) /* The object to convert. */
{
+ ThreadSpecificData *typeCache = GetTypeCache();
const Tcl_ObjType *typePtr;
const char *string;
char *rest;
@@ -688,23 +709,10 @@ SetMMFromAny(
int units;
MMRep *mmPtr;
- static const Tcl_ObjType *tclDoubleObjType = NULL;
- static const Tcl_ObjType *tclIntObjType = NULL;
-
- if (tclDoubleObjType == NULL) {
- /*
- * Cache the object types for comaprison below. This allows optimized
- * checks for standard cases.
- */
-
- tclDoubleObjType = Tcl_GetObjType("double");
- tclIntObjType = Tcl_GetObjType("int");
- }
-
- if (objPtr->typePtr == tclDoubleObjType) {
+ if (objPtr->typePtr == typeCache->doubleTypePtr) {
Tcl_GetDoubleFromObj(interp, objPtr, &d);
units = -1;
- } else if (objPtr->typePtr == tclIntObjType) {
+ } else if (objPtr->typePtr == typeCache->intTypePtr) {
Tcl_GetIntFromObj(interp, objPtr, &units);
d = (double) units;
units = -1;