]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
perf(compiler-vapor): combine effect
author三咲智子 Kevin Deng <sxzz@sxzz.moe>
Wed, 6 Dec 2023 17:09:03 +0000 (01:09 +0800)
committer三咲智子 Kevin Deng <sxzz@sxzz.moe>
Wed, 6 Dec 2023 17:11:25 +0000 (01:11 +0800)
packages/compiler-vapor/__tests__/__snapshots__/compile.test.ts.snap
packages/compiler-vapor/src/transform.ts

index 893ffc05b2954ff993d736936d281130425d0706..92164b013614b7acc21ff673f360ad8f41ed7c00 100644 (file)
@@ -328,14 +328,8 @@ export function render(_ctx) {
   _on(n4, "click", (...args) => (_ctx.handleClick && _ctx.handleClick(...args)))
   _effect(() => {
     _setText(n1, undefined, _ctx.count)
-  })
-  _effect(() => {
     _setText(n2, undefined, _ctx.count)
-  })
-  _effect(() => {
     _setText(n3, undefined, _ctx.count)
-  })
-  _effect(() => {
     _setAttr(n4, "id", undefined, _ctx.count)
   })
   return n0
index 4496df6e6a343c2b517dace85989f3a113c149f1..a5fa40ef27d0aefcd053172bca96ea553d7a6e9f 100644 (file)
@@ -113,11 +113,28 @@ function createRootContext(
       ) {
         return this.registerOperation(...operations)
       }
-      // TODO combine effects
-      effect.push({
-        expressions: expressions as IRExpression[],
-        operations,
-      })
+      const existing = effect.find((e) =>
+        isSameExpression(e.expressions, expressions as IRExpression[]),
+      )
+      if (existing) {
+        existing.operations.push(...operations)
+      } else {
+        effect.push({
+          expressions: expressions as IRExpression[],
+          operations,
+        })
+      }
+
+      function isSameExpression(a: IRExpression[], b: IRExpression[]) {
+        if (a.length !== b.length) return false
+        return a.every(
+          (exp, i) => identifyExpression(exp) === identifyExpression(b[i]),
+        )
+      }
+
+      function identifyExpression(exp: IRExpression) {
+        return typeof exp === 'string' ? exp : exp.content
+      }
     },
 
     template: '',