Skip to content

Commit 265dd45

Browse files
fnlctrlyyx990803
authored andcommitted
refactor(class-util): cache whitespace regex (vuejs#8743)
1 parent 4f111f9 commit 265dd45

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/platforms/web/runtime/class-util.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* @flow */
22

3+
const whitespaceRE = /\s+/
4+
35
/**
46
* Add class with compatibility for SVG since classList is not supported on
57
* SVG elements in IE
@@ -13,7 +15,7 @@ export function addClass (el: HTMLElement, cls: ?string) {
1315
/* istanbul ignore else */
1416
if (el.classList) {
1517
if (cls.indexOf(' ') > -1) {
16-
cls.split(/\s+/).forEach(c => el.classList.add(c))
18+
cls.split(whitespaceRE).forEach(c => el.classList.add(c))
1719
} else {
1820
el.classList.add(cls)
1921
}
@@ -38,7 +40,7 @@ export function removeClass (el: HTMLElement, cls: ?string) {
3840
/* istanbul ignore else */
3941
if (el.classList) {
4042
if (cls.indexOf(' ') > -1) {
41-
cls.split(/\s+/).forEach(c => el.classList.remove(c))
43+
cls.split(whitespaceRE).forEach(c => el.classList.remove(c))
4244
} else {
4345
el.classList.remove(cls)
4446
}

0 commit comments

Comments
 (0)