From e31d811cf563c0108e47e22cb6891badea646090 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Sat, 2 Oct 2010 00:21:12 -0600 Subject: [PATCH] Optimize DOM -> UID lookup in viewport --- imp/js/viewport.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/imp/js/viewport.js b/imp/js/viewport.js index 823904e96..c815ee617 100644 --- a/imp/js/viewport.js +++ b/imp/js/viewport.js @@ -1583,6 +1583,24 @@ ViewPort_Buffer = Class.create({ return this.rowlist.keys(); }, + domidsToUIDs: function(ids) + { + var i = 0, + idsize = ids.size(), + uids = []; + + this.data.each(function(d) { + if (d.value.VP_domid && ids.include(d.value.VP_domid)) { + uids.push(d.key); + if (++i == idsize) { + throw $break; + } + } + }); + + return uids; + }, + rowsToUIDs: function(rows) { return rows.collect(this.rowlist.get.bind(this.rowlist)).compact(); @@ -1732,7 +1750,7 @@ ViewPort_Selection = Class.create({ // Fall-through case 'domid': - return this._search({ VP_domid: { equal: d } }, this.buffer.getData(this.buffer.getAllUIDs())).get('uid'); + return this.buffer.domidsToUIDs(d); case 'rownum': return this.buffer.rowsToUIDs(d); -- 2.11.0