From: Jack Allnutt Date: Wed, 22 May 2013 09:08:14 +0000 (+0100) Subject: Optimise chanlist render() X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=6b2f04c8d3ea395e02a92687b68bb05a4f33c9f8;p=KiwiIRC.git 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. --- 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]); } });