background: get rid of nested loop when finishing file loading

At the moment when a file is loaded, we iterate through the list of
pending file loads and ignore any unrelated to the file, then iterate
all the callers of the related file loads and finish them.

In fact, there can only ever be one pending file load related to the
file, and we already know it, so we can avoid the ugly nested loops.

https://bugzilla.gnome.org/show_bug.cgi?id=722149
This commit is contained in:
Ray Strode 2014-02-26 16:09:26 -05:00 committed by Jasper St. Pierre
parent e917b7ce0f
commit fdf264ff64

View File

@ -178,28 +178,22 @@ const BackgroundCache = new Lang.Class({
content = null;
}
for (let i = 0; i < this._pendingFileLoads.length; i++) {
let pendingLoad = this._pendingFileLoads[i];
if (pendingLoad.filename != params.filename ||
pendingLoad.style != params.style)
continue;
for (let i = 0; i < fileLoad.callers.length; i++) {
let caller = fileLoad.callers[i];
if (caller.onFinished) {
let newContent;
for (let j = 0; j < pendingLoad.callers.length; j++) {
if (pendingLoad.callers[j].onFinished) {
let newContent;
if (content) {
newContent = content.copy(pendingLoad.callers[j].monitorIndex,
pendingLoad.callers[j].effects);
this._images.push(newContent);
}
pendingLoad.callers[j].onFinished(newContent);
if (content) {
newContent = content.copy(caller.monitorIndex, caller.effects);
this._images.push(newContent);
}
}
this._pendingFileLoads.splice(i, 1);
caller.onFinished(newContent);
}
}
let idx = this._pendingFileLoads.indexOf(fileLoad);
this._pendingFileLoads.splice(idx, 1);
}));
},