]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
perf: minor tweaks
authorEvan You <yyx990803@gmail.com>
Thu, 17 Oct 2019 03:12:57 +0000 (23:12 -0400)
committerEvan You <yyx990803@gmail.com>
Thu, 17 Oct 2019 19:02:15 +0000 (15:02 -0400)
packages/reactivity/src/baseHandlers.ts
packages/reactivity/src/computed.ts
packages/reactivity/src/effect.ts

index 0043af73fe5cc759c8d8593cfc5fb05f6b9bfb6e..4ebdb0a3354d3bf01b248a7a63298dde90ff6d1b 100644 (file)
@@ -12,8 +12,9 @@ const builtInSymbols = new Set(
 )
 
 function createGetter(isReadonly: boolean) {
-  return function get(target: any, key: string | symbol, receiver: any) {
-    const res = Reflect.get(target, key, receiver)
+  return function get(target: any, key: string | symbol) {
+    // not using Reflect.get here for perf reasons
+    const res = target[key]
     if (isSymbol(key) && builtInSymbols.has(key)) {
       return res
     }
index ec26028b2ed47762c38e4091a5696aca4c36da3b..c0af4a6478d20d7ea998bb742575a3978651aaf9 100644 (file)
@@ -1,4 +1,4 @@
-import { effect, ReactiveEffect, activeReactiveEffectStack } from './effect'
+import { effect, ReactiveEffect, effectStack } from './effect'
 import { Ref, UnwrapRef } from './ref'
 import { isFunction, NOOP } from '@vue/shared'
 
@@ -67,15 +67,15 @@ export function computed<T>(
 }
 
 function trackChildRun(childRunner: ReactiveEffect) {
-  const parentRunner =
-    activeReactiveEffectStack[activeReactiveEffectStack.length - 1]
-  if (parentRunner) {
-    for (let i = 0; i < childRunner.deps.length; i++) {
-      const dep = childRunner.deps[i]
-      if (!dep.has(parentRunner)) {
-        dep.add(parentRunner)
-        parentRunner.deps.push(dep)
-      }
+  if (effectStack.length === 0) {
+    return
+  }
+  const parentRunner = effectStack[effectStack.length - 1]
+  for (let i = 0; i < childRunner.deps.length; i++) {
+    const dep = childRunner.deps[i]
+    if (!dep.has(parentRunner)) {
+      dep.add(parentRunner)
+      parentRunner.deps.push(dep)
     }
   }
 }
index fac7180d158b0960df6690f92f95b88de123d46c..422d08e0154a01616639f19b72c7b4aad0ba10d5 100644 (file)
@@ -33,7 +33,7 @@ export interface DebuggerEvent {
   key: string | symbol | undefined
 }
 
-export const activeReactiveEffectStack: ReactiveEffect[] = []
+export const effectStack: ReactiveEffect[] = []
 
 export const ITERATE_KEY = Symbol('iterate')
 
@@ -88,13 +88,13 @@ function run(effect: ReactiveEffect, fn: Function, args: any[]): any {
   if (!effect.active) {
     return fn(...args)
   }
-  if (!activeReactiveEffectStack.includes(effect)) {
+  if (!effectStack.includes(effect)) {
     cleanup(effect)
     try {
-      activeReactiveEffectStack.push(effect)
+      effectStack.push(effect)
       return fn(...args)
     } finally {
-      activeReactiveEffectStack.pop()
+      effectStack.pop()
     }
   }
 }
@@ -124,13 +124,10 @@ export function track(
   type: OperationTypes,
   key?: string | symbol
 ) {
-  if (!shouldTrack) {
-    return
-  }
-  const effect = activeReactiveEffectStack[activeReactiveEffectStack.length - 1]
-  if (!effect) {
+  if (!shouldTrack || effectStack.length === 0) {
     return
   }
+  const effect = effectStack[effectStack.length - 1]
   if (type === OperationTypes.ITERATE) {
     key = ITERATE_KEY
   }