Bug 1318974 - Cleanup the _pendingMessages array even if getNextPendingMessage never returns null, r=aleth a=jorgk DONTBUILD
authorFlorian Quèze <florian@queze.net>
Mon, 21 Nov 2016 01:04:57 +0100
changeset 26819 49c1ec6b281d11d8c7417405340f85631aa47039
parent 26818 53c358c782fe6de7beb20139b0708998acd64261
child 26820 c3886b6e58e89e01b144e876d2df4f2a18754464
push id1834
push userclokep@gmail.com
push dateMon, 23 Jan 2017 21:48:40 +0000
treeherdercomm-beta@293cffe83e59 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaleth, jorgk
bugs1318974
Bug 1318974 - Cleanup the _pendingMessages array even if getNextPendingMessage never returns null, r=aleth a=jorgk DONTBUILD
chat/content/convbrowser.xml
--- a/chat/content/convbrowser.xml
+++ b/chat/content/convbrowser.xml
@@ -413,22 +413,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;
           ]]>