Parcourir la source

improve: optimize the performance of scheduler (#5607)

laoxiong il y a 9 ans
Parent
commit
5c0c8c8865
1 fichiers modifiés avec 3 ajouts et 3 suppressions
  1. 3 3
      src/core/observer/scheduler.js

+ 3 - 3
src/core/observer/scheduler.js

@@ -24,7 +24,7 @@ let index = 0
  * Reset the scheduler's state.
  */
 function resetSchedulerState () {
-  queue.length = activatedChildren.length = 0
+  index = queue.length = activatedChildren.length = 0
   has = {}
   if (process.env.NODE_ENV !== 'production') {
     circular = {}
@@ -134,10 +134,10 @@ export function queueWatcher (watcher: Watcher) {
       // if already flushing, splice the watcher based on its id
       // if already past its id, it will be run next immediately.
       let i = queue.length - 1
-      while (i >= 0 && queue[i].id > watcher.id) {
+      while (i > index && queue[i].id > watcher.id) {
         i--
       }
-      queue.splice(Math.max(i, index) + 1, 0, watcher)
+      queue.splice(i + 1, 0, watcher)
     }
     // queue the flush
     if (!waiting) {