From 054ccecd58c36b909661598f43a4056ed07e59c2 Mon Sep 17 00:00:00 2001 From: Andrew Talbot Date: Mon, 20 Apr 2020 15:44:20 -0400 Subject: [PATCH] perf(core): use `startsWith` instead of `indexOf` (#989) --- packages/runtime-core/src/componentEmits.ts | 2 +- packages/runtime-dom/src/modules/attrs.ts | 2 +- packages/runtime-dom/src/patchProp.ts | 2 +- packages/shared/src/normalizeProp.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/runtime-core/src/componentEmits.ts b/packages/runtime-core/src/componentEmits.ts index 228991b5..7b91bf34 100644 --- a/packages/runtime-core/src/componentEmits.ts +++ b/packages/runtime-core/src/componentEmits.ts @@ -73,7 +73,7 @@ export function emit( let handler = props[`on${capitalize(event)}`] // for v-model update:xxx events, also trigger kebab-case equivalent // for props passed via kebab-case - if (!handler && event.indexOf('update:') === 0) { + if (!handler && event.startsWith('update:')) { event = hyphenate(event) handler = props[`on${capitalize(event)}`] } diff --git a/packages/runtime-dom/src/modules/attrs.ts b/packages/runtime-dom/src/modules/attrs.ts index 10fe06af..b9bba846 100644 --- a/packages/runtime-dom/src/modules/attrs.ts +++ b/packages/runtime-dom/src/modules/attrs.ts @@ -8,7 +8,7 @@ export function patchAttr( value: any, isSVG: boolean ) { - if (isSVG && key.indexOf('xlink:') === 0) { + if (isSVG && key.startsWith('xlink:')) { if (value == null) { el.removeAttributeNS(xlinkNS, key.slice(6, key.length)) } else { diff --git a/packages/runtime-dom/src/patchProp.ts b/packages/runtime-dom/src/patchProp.ts index 4543bd1a..979f9f24 100644 --- a/packages/runtime-dom/src/patchProp.ts +++ b/packages/runtime-dom/src/patchProp.ts @@ -30,7 +30,7 @@ export const patchProp: RendererOptions['patchProp'] = ( default: if (isOn(key)) { // ignore v-model listeners - if (key.indexOf('onUpdate:') < 0) { + if (!key.startsWith('onUpdate:')) { patchEvent(el, key, prevValue, nextValue, parentComponent) } } else if ( diff --git a/packages/shared/src/normalizeProp.ts b/packages/shared/src/normalizeProp.ts index 201e4980..77357c68 100644 --- a/packages/shared/src/normalizeProp.ts +++ b/packages/shared/src/normalizeProp.ts @@ -29,7 +29,7 @@ export function stringifyStyle( } for (const key in styles) { const value = styles[key] - const normalizedKey = key.indexOf(`--`) === 0 ? key : hyphenate(key) + const normalizedKey = key.startsWith(`--`) ? key : hyphenate(key) if ( isString(value) || (typeof value === 'number' && isNoUnitNumericStyleProp(normalizedKey))