artur_biesiadow
13 years agoNew Contributor
Tree wItems.Item(x) extremly slow
We are trying to find out if given node exists in the tree. Application is running on jvm with SWT, but we are accessing underlying Windows tree control (as SWT is not supported very well). Way suggested in multiple posts was to iterate through wItems/Items and compare text labels. Unfortunately, it seems that calling Item(x) is taking considerable amount of time - in range of 200ms. This means that finding if given tree node exists in tree with 30 items takes 6 seconds...
I'm providing the code below. Wildcard match part is not taking any considerable time - when I have replaced it with direct comparison, execution time stays the same. Unscientific profiling (not that easy in TC given no ms display in timestamps) shows that time is spent in
var it = current.Item(x);
My feeling is that time might be spent in wrapping child into TC layer - but 200ms? Is there any way to speed things up? Or maybe, some better way to find if tree child exists?
Code is below
function TreeItemExists(tree, path)
{
var items, newPath, str, i;
if (aqString.SubString(path,0,1) =="|") {
path = aqString.SubString(path,1,path.length-1);
}
items = path.split("|");
newPath = "";
var current = tree.wItems;
for (i=0; i<items.length; i++) {
var x;
for ( x=0; x < current.Count; x++ ) {
var it = current.Item(x);
if (wildcardMatch(items,it.Text)) {
if ( i == items.length -1 ) {
Log.Message("Item " + path + " found in tree");
return true;
}
current = it.Items;
break;
}
}
if ( !current || x == current.Count) {
Log.Message("Item " + path + " not found in tree");
return false;
}
newPath = newPath + "|" + items;
tree.ExpandItem(newPath);
}
Log.Error("Should never reach here");
}
I'm providing the code below. Wildcard match part is not taking any considerable time - when I have replaced it with direct comparison, execution time stays the same. Unscientific profiling (not that easy in TC given no ms display in timestamps) shows that time is spent in
var it = current.Item(x);
My feeling is that time might be spent in wrapping child into TC layer - but 200ms? Is there any way to speed things up? Or maybe, some better way to find if tree child exists?
Code is below
function TreeItemExists(tree, path)
{
var items, newPath, str, i;
if (aqString.SubString(path,0,1) =="|") {
path = aqString.SubString(path,1,path.length-1);
}
items = path.split("|");
newPath = "";
var current = tree.wItems;
for (i=0; i<items.length; i++) {
var x;
for ( x=0; x < current.Count; x++ ) {
var it = current.Item(x);
if (wildcardMatch(items,it.Text)) {
if ( i == items.length -1 ) {
Log.Message("Item " + path + " found in tree");
return true;
}
current = it.Items;
break;
}
}
if ( !current || x == current.Count) {
Log.Message("Item " + path + " not found in tree");
return false;
}
newPath = newPath + "|" + items;
tree.ExpandItem(newPath);
}
Log.Error("Should never reach here");
}