Bug 1318974 - Cleanup the _pendingMessages array even if getNextPendingMessage never returns null, r=aleth. a=aleth CLOSED TREE
authorFlorian Quèze <florian@queze.net>
Mon, 21 Nov 2016 01:04:57 +0100
changeset 20732 d4e762ef561de865b6e95befb61beafaf914866d
parent 20731 09ec3012ff3d5d3ea84338b2d7707046046bdcbc
child 20733 b11789455e43844c9023262ddc34b992db99b082
push id12551
push useraleth@instantbird.org
push dateMon, 21 Nov 2016 00:19:05 +0000
treeherdercomm-central@d4e762ef561d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaleth, aleth
bugs1318974
Bug 1318974 - Cleanup the _pendingMessages array even if getNextPendingMessage never returns null, r=aleth. a=aleth CLOSED TREE
chat/content/convbrowser.xml
--- a/chat/content/convbrowser.xml
+++ b/chat/content/convbrowser.xml
@@ -412,22 +412,28 @@
            with something else. The log viewer for example uses an
            enumerator that creates message objects lazily to avoid
            jank when displaying lots of messages. -->
       <!-- This variable is reset in onStateChange. -->
       <field name="_nextPendingMessageIndex">0</field>
       <method name="getNextPendingMessage">
         <body>
           <![CDATA[
-            if (this._nextPendingMessageIndex == this._pendingMessages.length) {
+            let length = this._pendingMessages.length;
+            if (this._nextPendingMessageIndex == length)
+              return null;
+
+            let result = this._pendingMessages[this._nextPendingMessageIndex++];
+
+            if (this._nextPendingMessageIndex == length) {
               this._pendingMessages = [];
               this._nextPendingMessageIndex = 0;
-              return null;
             }
-            return this._pendingMessages[this._nextPendingMessageIndex++];
+
+            return result;
           ]]>
         </body>
       </method>
       <method name="getPendingMessagesCount">
         <body>
           <![CDATA[
             return this._pendingMessages.length;
           ]]>