瀏覽代碼

perf(reactivity): only call Set.add if doesn't already have value (#3307)

zhufengzhufeng 5 年之前
父節點
當前提交
9cd988342c
共有 1 個文件被更改,包括 1 次插入1 次删除
  1. 1 1
      packages/reactivity/src/collectionHandlers.ts

+ 1 - 1
packages/reactivity/src/collectionHandlers.ts

@@ -76,8 +76,8 @@ function add(this: SetTypes, value: unknown) {
   const target = toRaw(this)
   const target = toRaw(this)
   const proto = getProto(target)
   const proto = getProto(target)
   const hadKey = proto.has.call(target, value)
   const hadKey = proto.has.call(target, value)
-  target.add(value)
   if (!hadKey) {
   if (!hadKey) {
+    target.add(value)
     trigger(target, TriggerOpTypes.ADD, value, value)
     trigger(target, TriggerOpTypes.ADD, value, value)
   }
   }
   return this
   return this