[gnome-shell] searchDisplay: don't create useless SearchResult's
- From: Maxim Ermilov <mermilov src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] searchDisplay: don't create useless SearchResult's
- Date: Mon, 21 Mar 2011 23:51:48 +0000 (UTC)
commit 12bd3744776ebdb52fef960b5d26cee22e5f9c08
Author: Maxim Ermilov <zaspire rambler ru>
Date: Tue Mar 22 01:53:07 2011 +0300
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
js/ui/iconGrid.js | 4 ++++
js/ui/searchDisplay.js | 35 +++++++++++++++++++++++++++++------
2 files changed, 33 insertions(+), 6 deletions(-)
---
diff --git a/js/ui/iconGrid.js b/js/ui/iconGrid.js
index 3cdc712..c6deb19 100644
--- a/js/ui/iconGrid.js
+++ b/js/ui/iconGrid.js
@@ -281,6 +281,10 @@ IconGrid.prototype = {
}
},
+ childrenInRow: function(rowWidth) {
+ return this._computeLayout(rowWidth)[0];
+ },
+
_computeLayout: function (forWidth) {
let nColumns = 0;
let usedWidth = 0;
diff --git a/js/ui/searchDisplay.js b/js/ui/searchDisplay.js
index 81fd89b..f3d463a 100644
--- a/js/ui/searchDisplay.js
+++ b/js/ui/searchDisplay.js
@@ -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;
},
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]