From 6b2f04c8d3ea395e02a92687b68bb05a4f33c9f8 Mon Sep 17 00:00:00 2001 From: Jack Allnutt Date: Wed, 22 May 2013 10:08:14 +0100 Subject: [PATCH] Optimise chanlist render() Don't loop over all channels as head of channel list is in the same order as the DOM. Use a for loop to append the channel rows instead of _.each to avoid overhead of function call. --- client/assets/dev/applet_chanlist.js | 29 ++++++++++++---------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/client/assets/dev/applet_chanlist.js b/client/assets/dev/applet_chanlist.js index 698d857..97db49d 100644 --- a/client/assets/dev/applet_chanlist.js +++ b/client/assets/dev/applet_chanlist.js @@ -26,20 +26,15 @@ render: function () { var table = $('table', this.$el), tbody = table.children('tbody:first').detach(), - that = this; - if (!this.isIE) { - tbody.children().each(function (idx, child) { - var i, chan, - channels_length = that.channels.length; - chan = $(child.querySelector('.chan')).data('channel'); - for (i = 0; i < channels_length; i++) { - if (that.channels[i].channel === chan) { - that.channels[i].dom = tbody[0].removeChild(child); - break; - } - } - }); - } + that = this, + channels_length = this.channels.length, + i; + + tbody.children().each(function (idx, child) { + if (that.channels[idx].channel === $(child.querySelector('.chan')).data('channel')) { + that.channels[idx].dom = tbody[0].removeChild(child); + } + }); if (this.ordered) { this.channels.sort(function (a, b) { @@ -47,9 +42,9 @@ }); } - _.each(this.channels, function (chan) { - tbody[0].appendChild(chan.dom); - }); + for (i = 0; i < channels_length; i++) { + tbody[0].appendChild(this.channels[i].dom); + } table[0].appendChild(tbody[0]); } }); -- 2.25.1