Optimise chanlist render()
authorJack Allnutt <m2ys4u@gmail.com>
Wed, 22 May 2013 09:08:14 +0000 (10:08 +0100)
committerJack Allnutt <m2ys4u@gmail.com>
Wed, 22 May 2013 09:08:14 +0000 (10:08 +0100)
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

index 698d857f26d362b3c367711dffccae64a76482e6..97db49d5bded2ca6142e761404a791a00917bb12 100644 (file)
         render: function () {\r
             var table = $('table', this.$el),\r
                 tbody = table.children('tbody:first').detach(),\r
-                that = this;\r
-            if (!this.isIE) {\r
-                tbody.children().each(function (idx, child) {\r
-                    var i, chan,\r
-                        channels_length = that.channels.length;\r
-                    chan = $(child.querySelector('.chan')).data('channel');\r
-                    for (i = 0; i < channels_length; i++) {\r
-                        if (that.channels[i].channel === chan) {\r
-                            that.channels[i].dom = tbody[0].removeChild(child);\r
-                            break;\r
-                        }\r
-                    }\r
-                });\r
-            }\r
+                that = this,\r
+                channels_length = this.channels.length,\r
+                i;\r
+\r
+            tbody.children().each(function (idx, child) {\r
+                if (that.channels[idx].channel === $(child.querySelector('.chan')).data('channel')) {\r
+                    that.channels[idx].dom = tbody[0].removeChild(child);\r
+                }\r
+            });\r
 \r
             if (this.ordered) {\r
                 this.channels.sort(function (a, b) {\r
@@ -47,9 +42,9 @@
                 });\r
             }\r
 \r
-            _.each(this.channels, function (chan) {\r
-                tbody[0].appendChild(chan.dom);\r
-            });\r
+            for (i = 0; i < channels_length; i++) {\r
+                tbody[0].appendChild(this.channels[i].dom);\r
+            }\r
             table[0].appendChild(tbody[0]);\r
         }\r
     });\r