summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2011-11-02 09:25:53 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2011-11-02 09:25:53 (GMT)
commit4425617a46ed8ed66c18049cf2514547a8b2290d (patch)
treefa56526152c20e6c12f5bf97153b419181797081 /generic
parent001ae23c00c84af98a880e6f37b976d94aa7b6fe (diff)
downloadtk-4425617a46ed8ed66c18049cf2514547a8b2290d.zip
tk-4425617a46ed8ed66c18049cf2514547a8b2290d.tar.gz
tk-4425617a46ed8ed66c18049cf2514547a8b2290d.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 cb222cb..4c8516e 100644
--- a/generic/tkObj.c
+++ b/generic/tkObj.c
@@ -48,8 +48,8 @@ typedef struct PixelRep {
*/
typedef struct ThreadSpecificData {
- Tcl_ObjType *doubleTypePtr;
- Tcl_ObjType *intTypePtr;
+ const Tcl_ObjType *doubleTypePtr;
+ const Tcl_ObjType *intTypePtr;
} ThreadSpecificData;
static Tcl_ThreadDataKey dataKey;
@@ -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 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()
+{
+ ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
+ 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,13 +204,7 @@ GetPixelsFromObjEx(
*/
if (objPtr->typePtr != &pixelObjType) {
- ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
- Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
-
- if (tsdPtr->doubleTypePtr == NULL) {
- tsdPtr->doubleTypePtr = Tcl_GetObjType("double");
- tsdPtr->intTypePtr = Tcl_GetObjType("int");
- }
+ ThreadSpecificData *tsdPtr = GetTypeCache();
if (objPtr->typePtr == tsdPtr->doubleTypePtr) {
(void) Tcl_GetDoubleFromObj(interp, objPtr, &d);
@@ -687,29 +707,17 @@ SetMMFromAny(
Tcl_Interp *interp, /* Used for error reporting if not NULL. */
Tcl_Obj *objPtr) /* The object to convert. */
{
+ ThreadSpecificData *tsdPtr = GetTypeCache();
const Tcl_ObjType *typePtr;
char *string, *rest;
double d;
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 == tsdPtr->doubleTypePtr) {
Tcl_GetDoubleFromObj(interp, objPtr, &d);
units = -1;
- } else if (objPtr->typePtr == tclIntObjType) {
+ } else if (objPtr->typePtr == tsdPtr->intTypePtr) {
Tcl_GetIntFromObj(interp, objPtr, &units);
d = (double) units;
units = -1;