Menu

#1801 Empty test performance issue from c.l.t

obsolete: 8.4.6
open
5
2004-11-30
2004-11-30
No

From: Khamis Abuelkomboz <khamis@wellcode.com>
Newsgroups: comp.lang.tcl
Subject: performace issue in Tk
Date: Mon, 29 Nov 2004 22:15:50 +0100
Organization: T-Online
Message-ID: <cog3i6$ip4$05$1@news.t-online.com>

Hi

I have found a performance and memory usage issue in
the function ObjectIsEmpty implemented in
tk8.4.6\generic\tkConfig.c:2229

To test if an object is empty it just convert every
object into a string. this is pretty ugly, if
you have lists in the options list. it converts all
lists, integers and so on into strings. as
example, with my fix I reduced memory usage from 200MB
to 110MB by large amount of data. It got even
some factors faster.

here is the origin

static int
ObjectIsEmpty(objPtr)
Tcl_Obj *objPtr; /* Object to test. May be NULL. */
{
int length;

if (objPtr == NULL) {
return 1;
}
if (objPtr->bytes != NULL) {
return (objPtr->length == 0);
}
Tcl_GetStringFromObj(objPtr, &length);
return (length == 0);
}

and the modified version

static int
ObjectIsEmpty(objPtr)
Tcl_Obj *objPtr; /* Object to test. May be NULL. */
{
int length;

if (objPtr == NULL) {
return 1;
}
if (objPtr->bytes != NULL) {
return (objPtr->length == 0);
}
++++++>>>>>>>
if (objPtr->typePtr != NULL)
{
if (stricmp(objPtr->typePtr->name, "list") == 0)
{
List *listRepPtr = (List *)
objPtr->internalRep.twoPtrValue.ptr1;
int numElems = listRepPtr->elemCount;
return (numElems == 0);
}
if (stricmp(objPtr->typePtr->name, "string") != 0)
return 0;
}
++++++<<<<<<<<
Tcl_GetStringFromObj(objPtr, &length);
return (length == 0);
}

--
Try Code-Navigator on http://www.codenav.com
a source code navigating, analysis and developing tool.
It supports almost all languages on the scope.

Discussion