]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
perf: optimize on* prop check
authorEvan You <yyx990803@gmail.com>
Thu, 30 Nov 2023 09:51:58 +0000 (17:51 +0800)
committerEvan You <yyx990803@gmail.com>
Thu, 30 Nov 2023 09:52:51 +0000 (17:52 +0800)
packages/runtime-dom/src/patchProp.ts
packages/shared/src/general.ts

index 15f4f73edc47a5b31c6f725559286bb2f6395eab..28753a90380e8a532f8eb7887ed4dd86a9ec2997 100644 (file)
@@ -6,7 +6,12 @@ import { patchEvent } from './modules/events'
 import { isOn, isString, isFunction, isModelListener } from '@vue/shared'
 import { RendererOptions } from '@vue/runtime-core'
 
-const nativeOnRE = /^on[a-z]/
+const isNativeOn = (key: string) =>
+  key.charCodeAt(0) === 111 /* o */ &&
+  key.charCodeAt(1) === 110 /* n */ &&
+  // lowercase letter
+  key.charCodeAt(2) > 96 &&
+  key.charCodeAt(2) < 123
 
 const embeddedTags = ['IMG', 'VIDEO', 'CANVAS', 'SOURCE']
 
@@ -75,7 +80,7 @@ function shouldSetAsProp(
       return true
     }
     // or native onclick with function values
-    if (key in el && nativeOnRE.test(key) && isFunction(value)) {
+    if (key in el && isNativeOn(key) && isFunction(value)) {
       return true
     }
     return false
@@ -116,7 +121,7 @@ function shouldSetAsProp(
   }
 
   // native onclick with string value, must be set as attribute
-  if (nativeOnRE.test(key) && isString(value)) {
+  if (isNativeOn(key) && isString(value)) {
     return false
   }
 
index 50e7eb427288a7c436117964b5a852ab99245d3e..dcde4c8c6cc98b27b0d5d4844d3fa33718cdacb0 100644 (file)
@@ -12,8 +12,11 @@ export const NOOP = () => {}
  */
 export const NO = () => false
 
-const onRE = /^on[^a-z]/
-export const isOn = (key: string) => onRE.test(key)
+export const isOn = (key: string) =>
+  key.charCodeAt(0) === 111 /* o */ &&
+  key.charCodeAt(1) === 110 /* n */ &&
+  // uppercase letter
+  (key.charCodeAt(2) > 122 || key.charCodeAt(2) < 97)
 
 export const isModelListener = (key: string) => key.startsWith('onUpdate:')