From 19ea77aff7a1f48075b002e882dffcabfe0919d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8A=B1=E6=9E=9C=E5=B1=B1=E5=A4=A7=E5=9C=A3?= <316783812@qq.com> Date: Fri, 11 Nov 2022 09:15:37 +0800 Subject: [PATCH] refactor: more concise bitwise operations for flag removal (#7092) --- packages/runtime-core/src/components/KeepAlive.ts | 11 +++-------- packages/runtime-core/src/vnode.ts | 10 +++------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/packages/runtime-core/src/components/KeepAlive.ts b/packages/runtime-core/src/components/KeepAlive.ts index 3fec48140fc..66d0f82a10e 100644 --- a/packages/runtime-core/src/components/KeepAlive.ts +++ b/packages/runtime-core/src/components/KeepAlive.ts @@ -424,14 +424,9 @@ function injectToKeepAliveRoot( } function resetShapeFlag(vnode: VNode) { - let shapeFlag = vnode.shapeFlag - if (shapeFlag & ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE) { - shapeFlag -= ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE - } - if (shapeFlag & ShapeFlags.COMPONENT_KEPT_ALIVE) { - shapeFlag -= ShapeFlags.COMPONENT_KEPT_ALIVE - } - vnode.shapeFlag = shapeFlag + // bitwise operations to remove keep alive flags + vnode.shapeFlag &= ~ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE + vnode.shapeFlag &= ~ShapeFlags.COMPONENT_KEPT_ALIVE } function getInnerChild(vnode: VNode) { diff --git a/packages/runtime-core/src/vnode.ts b/packages/runtime-core/src/vnode.ts index 41f848e44de..7d873f5a125 100644 --- a/packages/runtime-core/src/vnode.ts +++ b/packages/runtime-core/src/vnode.ts @@ -358,13 +358,9 @@ export function isSameVNodeType(n1: VNode, n2: VNode): boolean { hmrDirtyComponents.has(n2.type as ConcreteComponent) ) { // #7042, ensure the vnode being unmounted during HMR - if (n1.shapeFlag & ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE) { - n1.shapeFlag -= ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE - } - // #7042, ensure the vnode being mounted as fresh during HMR - if (n2.shapeFlag & ShapeFlags.COMPONENT_KEPT_ALIVE) { - n2.shapeFlag -= ShapeFlags.COMPONENT_KEPT_ALIVE - } + // bitwise operations to remove keep alive flags + n1.shapeFlag &= ~ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE + n2.shapeFlag &= ~ShapeFlags.COMPONENT_KEPT_ALIVE // HMR only: if the component has been hot-updated, force a reload. return false }