Skip to content

Commit e2654fb

Browse files
authored
Merge pull request #84 from hyperz111/fast-dashify
perf: use fast dashify function in `parser.js`
2 parents 25a9a0a + 22acc6f commit e2654fb

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

parser.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,28 @@ let UNITLESS = {
2727
'stroke-width': true
2828
}
2929

30+
let { fromCharCode } = String;
31+
3032
function dashify(str) {
31-
return str
32-
.replace(/([A-Z])/g, '-$1')
33-
.replace(/^ms-/, '-ms-')
34-
.toLowerCase()
33+
let result = '';
34+
let i = 0;
35+
let len = str.length;
36+
let code;
37+
38+
if (str[0] === 'm' && str[1] === 's') result += fromCharCode(45); // '-'
39+
40+
for (; i < len; i++) {
41+
code = str[i].charCodeAt(0);
42+
43+
if (code > 64 && code < 91) {
44+
result += fromCharCode(45) + fromCharCode(code + 32);
45+
continue;
46+
}
47+
48+
result += fromCharCode(code);
49+
}
50+
51+
return result;
3552
}
3653

3754
function decl(parent, name, value) {

0 commit comments

Comments
 (0)