From 22acc6ffd9fe5d2db5bd210a930fb680b8368c53 Mon Sep 17 00:00:00 2001 From: hyperz111 Date: Sun, 7 Dec 2025 14:05:49 +0700 Subject: [PATCH] use fast dashify function in parser.js --- parser.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/parser.js b/parser.js index 906039b..3cac15d 100644 --- a/parser.js +++ b/parser.js @@ -27,11 +27,28 @@ let UNITLESS = { 'stroke-width': true } +let { fromCharCode } = String; + function dashify(str) { - return str - .replace(/([A-Z])/g, '-$1') - .replace(/^ms-/, '-ms-') - .toLowerCase() + let result = ''; + let i = 0; + let len = str.length; + let code; + + if (str[0] === 'm' && str[1] === 's') result += fromCharCode(45); // '-' + + for (; i < len; i++) { + code = str[i].charCodeAt(0); + + if (code > 64 && code < 91) { + result += fromCharCode(45) + fromCharCode(code + 32); + continue; + } + + result += fromCharCode(code); + } + + return result; } function decl(parent, name, value) {