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:
parent
9ef4cc0ab9
commit
12bd374477
@ -281,6 +281,10 @@ IconGrid.prototype = {
|
||||
}
|
||||
},
|
||||
|
||||
childrenInRow: function(rowWidth) {
|
||||
return this._computeLayout(rowWidth)[0];
|
||||
},
|
||||
|
||||
_computeLayout: function (forWidth) {
|
||||
let nColumns = 0;
|
||||
let usedWidth = 0;
|
||||
|
@ -5,6 +5,7 @@ const Lang = imports.lang;
|
||||
const Gettext = imports.gettext.domain('gnome-shell');
|
||||
const _ = Gettext.gettext;
|
||||
const Gtk = imports.gi.Gtk;
|
||||
const Meta = imports.gi.Meta;
|
||||
const St = imports.gi.St;
|
||||
|
||||
const DND = imports.ui.dnd;
|
||||
@ -104,8 +105,30 @@ GridSearchResults.prototype = {
|
||||
this._grid = new IconGrid.IconGrid({ rowLimit: MAX_SEARCH_RESULTS_ROWS,
|
||||
xAlign: St.Align.START });
|
||||
this.actor = new St.Bin({ x_align: St.Align.START });
|
||||
|
||||
this.actor.set_child(this._grid.actor);
|
||||
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() {
|
||||
@ -113,15 +136,15 @@ GridSearchResults.prototype = {
|
||||
},
|
||||
|
||||
renderResults: function(results, terms) {
|
||||
for (let i = 0; i < results.length; i++) {
|
||||
let result = results[i];
|
||||
let meta = this.provider.getResultMeta(result);
|
||||
let display = new SearchResult(this.provider, meta, terms);
|
||||
this._grid.addItem(display.actor);
|
||||
}
|
||||
// copy the lists
|
||||
this._notDisplayedResult = results.slice(0);
|
||||
this._terms = terms.slice(0);
|
||||
this._tryAddResults();
|
||||
},
|
||||
|
||||
clear: function () {
|
||||
this._terms = [];
|
||||
this._notDisplayedResult = [];
|
||||
this._grid.removeAll();
|
||||
this.selectionIndex = -1;
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user