copy the ugly "seach the tree" triple loop to the places its used as that allows us to perform optimizations for each case, like searching the attached items first in item()

svn path=/trunk/KDE/kdelibs/; revision=980036
This commit is contained in:
Aaron J. Seigo 2009-06-10 23:27:35 +00:00
parent df45adfbe9
commit 4a96c20195

View File

@ -166,9 +166,17 @@ QList<ExtenderItem*> Extender::detachedItems() const
{
QList<ExtenderItem*> result;
foreach (ExtenderItem *item, items()) {
if (item->isDetached()) {
result.append(item);
//FIXME: a triple nested loop ... ew. there should be a more efficient way to do this
//iterate through all extenders we can find and check each extenders source applet.
foreach (Containment *c, d->applet->containment()->corona()->containments()) {
foreach (Applet *applet, c->applets()) {
if (applet->d->extender) {
foreach (ExtenderItem *item, applet->d->extender->attachedItems()) {
if (item->d->sourceApplet == d->applet && item->isDetached()) {
result.append(item);
}
}
}
}
}
@ -177,12 +185,33 @@ QList<ExtenderItem*> Extender::detachedItems() const
ExtenderItem *Extender::item(const QString &name) const
{
foreach (ExtenderItem *item, items()) {
if (item->name() == name) {
// chances are the item is in our own extender, so check there first
foreach (ExtenderItem *item, d->attachedExtenderItems) {
if (item->d->sourceApplet == d->applet && item->name() == name) {
return item;
}
}
// maybe it's been moved elsewhere, so lets search through the entire tree of elements
//FIXME: a triple nested loop ... ew. there should be a more efficient way to do this
//iterate through all extenders we can find and check each extenders source applet.
foreach (Containment *c, d->applet->containment()->corona()->containments()) {
foreach (Applet *applet, c->applets()) {
if (applet->d->extender) {
if (applet->d->extender == this) {
// skip it, we checked it already
continue;
}
foreach (ExtenderItem *item, applet->d->extender->attachedItems()) {
if (item->d->sourceApplet == d->applet && item->name() == name) {
return item;
}
}
}
}
}
return 0;
}