From 14ee9e74bf68024fcb53c305b1f15c6aab6e89d3 Mon Sep 17 00:00:00 2001 From: Liwei Qian Date: Wed, 6 Sep 2017 03:48:43 +0800 Subject: [PATCH] perf: optimize the performance of hyphenate method. (#6274) --- src/shared/util.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/shared/util.js b/src/shared/util.js index 4cf81eeb389..709fe146403 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -157,12 +157,9 @@ export const capitalize = cached((str: string): string => { /** * Hyphenate a camelCase string. */ -const hyphenateRE = /([^-])([A-Z])/g +const hyphenateRE = /\B([A-Z])/g export const hyphenate = cached((str: string): string => { - return str - .replace(hyphenateRE, '$1-$2') - .replace(hyphenateRE, '$1-$2') - .toLowerCase() + return str.replace(hyphenateRE, '-$1').toLowerCase() }) /**