searchDisplay: don't create useless SearchResult's

average constructing time for 1 SearchResult is 3 ms.
It give > 400 result on query like 'a' (on my machine).
https://bugzilla.gnome.org/show_bug.cgi?id=645313
This commit is contained in:
Maxim Ermilov 2011-03-22 01:53:07 +03:00
parent 9ef4cc0ab9
commit 12bd374477
2 changed files with 33 additions and 6 deletions

View File

@ -281,6 +281,10 @@ IconGrid.prototype = {
} }
}, },
childrenInRow: function(rowWidth) {
return this._computeLayout(rowWidth)[0];
},
_computeLayout: function (forWidth) { _computeLayout: function (forWidth) {
let nColumns = 0; let nColumns = 0;
let usedWidth = 0; let usedWidth = 0;

View File

@ -5,6 +5,7 @@ const Lang = imports.lang;
const Gettext = imports.gettext.domain('gnome-shell'); const Gettext = imports.gettext.domain('gnome-shell');
const _ = Gettext.gettext; const _ = Gettext.gettext;
const Gtk = imports.gi.Gtk; const Gtk = imports.gi.Gtk;
const Meta = imports.gi.Meta;
const St = imports.gi.St; const St = imports.gi.St;
const DND = imports.ui.dnd; const DND = imports.ui.dnd;
@ -104,8 +105,30 @@ GridSearchResults.prototype = {
this._grid = new IconGrid.IconGrid({ rowLimit: MAX_SEARCH_RESULTS_ROWS, this._grid = new IconGrid.IconGrid({ rowLimit: MAX_SEARCH_RESULTS_ROWS,
xAlign: St.Align.START }); xAlign: St.Align.START });
this.actor = new St.Bin({ x_align: St.Align.START }); this.actor = new St.Bin({ x_align: St.Align.START });
this.actor.set_child(this._grid.actor); this.actor.set_child(this._grid.actor);
this.selectionIndex = -1; this.selectionIndex = -1;
this._width = 0;
this.actor.connect('notify::width', Lang.bind(this, function() {
this._width = this.actor.width;
Meta.later_add(Meta.LaterType.BEFORE_REDRAW, Lang.bind(this, function() {
this._tryAddResults();
}));
}));
this._notDisplayedResult = [];
this._terms = [];
},
_tryAddResults: function() {
let canDisplay = this._grid.childrenInRow(this._width) * MAX_SEARCH_RESULTS_ROWS
- this._grid.visibleItemsCount();
for (let i = Math.min(this._notDisplayedResult.length, canDisplay); i > 0; i--) {
let result = this._notDisplayedResult.shift();
let meta = this.provider.getResultMeta(result);
let display = new SearchResult(this.provider, meta, this._terms);
this._grid.addItem(display.actor);
}
}, },
getVisibleResultCount: function() { getVisibleResultCount: function() {
@ -113,15 +136,15 @@ GridSearchResults.prototype = {
}, },
renderResults: function(results, terms) { renderResults: function(results, terms) {
for (let i = 0; i < results.length; i++) { // copy the lists
let result = results[i]; this._notDisplayedResult = results.slice(0);
let meta = this.provider.getResultMeta(result); this._terms = terms.slice(0);
let display = new SearchResult(this.provider, meta, terms); this._tryAddResults();
this._grid.addItem(display.actor);
}
}, },
clear: function () { clear: function () {
this._terms = [];
this._notDisplayedResult = [];
this._grid.removeAll(); this._grid.removeAll();
this.selectionIndex = -1; this.selectionIndex = -1;
}, },