Преглед изворни кода

perf: optimize the performance of hyphenate method. (#6274)

Liwei Qian пре 8 година
родитељ
комит
14ee9e74bf
1 измењених фајлова са 2 додато и 5 уклоњено
  1. 2 5
      src/shared/util.js

+ 2 - 5
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()
 })
 
 /**