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 27665 5af3facabea75a661b9e3a76c67e0717cd302ff8
parent 27664 a2dfa6e67d4f714f0e6f7ac3aabde1505f4bbb61
child 27666 c055a7873e95176deddeb7ced6ef574e91cdc6f2
push id1850
push userclokep@gmail.com
push dateWed, 08 Mar 2017 19:29:12 +0000
treeherdercomm-esr52@028df196b2d9 [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;
           ]]>