Apply patch 3224663 for Tcl - NULL value fixes and performance improvements for classes with many methods.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12563 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
d68b786b19
commit
60a1c5eed3
6 changed files with 64 additions and 8 deletions
|
|
@ -49,6 +49,7 @@ typedef struct swig_class {
|
|||
struct swig_class **bases;
|
||||
const char **base_names;
|
||||
swig_module_info *module;
|
||||
Tcl_HashTable hashtable;
|
||||
} swig_class;
|
||||
|
||||
typedef struct swig_instance {
|
||||
|
|
|
|||
|
|
@ -67,6 +67,28 @@ SWIG_Tcl_InstallConstants(Tcl_Interp *interp, swig_const_info constants[]) {
|
|||
}
|
||||
}
|
||||
|
||||
/* Create fast method lookup tables */
|
||||
|
||||
SWIGINTERN void
|
||||
SWIG_Tcl_InstallMethodLookupTables(Tcl_Interp *interp) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < swig_module.size; ++i) {
|
||||
swig_type_info *type = swig_module.type_initial[i];
|
||||
if (type->clientdata) {
|
||||
swig_class* klass = (swig_class*) type->clientdata;
|
||||
Tcl_InitHashTable(&(klass->hashtable), TCL_STRING_KEYS);
|
||||
swig_method* meth = klass->methods;
|
||||
while (meth && meth->name) {
|
||||
int newEntry;
|
||||
Tcl_HashEntry* hashentry = Tcl_CreateHashEntry(&(klass->hashtable), meth->name, &newEntry);
|
||||
Tcl_SetHashValue(hashentry, (ClientData)meth->method);
|
||||
++meth;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -113,6 +135,7 @@ SWIGEXPORT int SWIG_init(Tcl_Interp *interp) {
|
|||
}
|
||||
|
||||
SWIG_Tcl_InstallConstants(interp, swig_constants);
|
||||
SWIG_Tcl_InstallMethodLookupTables(interp);
|
||||
|
||||
%}
|
||||
|
||||
|
|
|
|||
|
|
@ -367,19 +367,17 @@ SWIG_Tcl_MethodCommand(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_
|
|||
}
|
||||
cls_stack_bi[cls_stack_top]++;
|
||||
|
||||
meth = cls->methods;
|
||||
/* Check for methods */
|
||||
while (meth && meth->name) {
|
||||
if (strcmp(meth->name,method) == 0) {
|
||||
Tcl_HashEntry* hashentry = Tcl_FindHashEntry(&(cls->hashtable), method);
|
||||
if (hashentry) {
|
||||
ClientData cd = Tcl_GetHashValue(hashentry);
|
||||
swig_wrapper method_wrapper = (swig_wrapper)cd;
|
||||
oldarg = objv[1];
|
||||
objv[1] = inst->thisptr;
|
||||
Tcl_IncrRefCount(inst->thisptr);
|
||||
rcode = (*meth->method)(clientData,interp,objc,objv);
|
||||
rcode = (method_wrapper)(clientData,interp,objc,objv);
|
||||
objv[1] = oldarg;
|
||||
Tcl_DecrRefCount(inst->thisptr);
|
||||
return rcode;
|
||||
}
|
||||
meth++;
|
||||
}
|
||||
/* Check class methods for a match */
|
||||
if (strcmp(method,"cget") == 0) {
|
||||
|
|
@ -486,7 +484,7 @@ SWIGRUNTIME Tcl_Obj *
|
|||
SWIG_Tcl_NewInstanceObj(Tcl_Interp *interp, void *thisvalue, swig_type_info *type, int flags) {
|
||||
Tcl_Obj *robj = SWIG_NewPointerObj(thisvalue, type,0);
|
||||
/* Check to see if this pointer belongs to a class or not */
|
||||
if ((type->clientdata) && (interp)) {
|
||||
if (thisvalue && (type->clientdata) && (interp)) {
|
||||
Tcl_CmdInfo ci;
|
||||
char *name;
|
||||
name = Tcl_GetStringFromObj(robj,NULL);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue