-
-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor/perf: regexp & split shorthand #34
Conversation
const matchOld = str.match(rFrontMatter); | ||
if (matchOld) { | ||
return { | ||
data: matchOld[2], | ||
content: matchOld[3] || '', | ||
separator: matchOld[1], | ||
prefixSeparator: true | ||
}; | ||
} | ||
|
||
function splitOld(str) { | ||
const match = str.match(rFrontMatter); | ||
if (rPrefixSep.test(str)) return { content: str }; | ||
|
||
return { | ||
data: match[2], | ||
content: match[3] || '', | ||
separator: match[1], | ||
prefixSeparator: true | ||
}; | ||
} | ||
const matchNew = str.match(rFrontMatterNew); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before
- old: test old pattern -> match old pattern
- new: test old pattern -> test new pattern -> match new pattern
After:
- old: match old pattern
- new: match old pattern -> match new pattern
As I find out in hexojs/hexo#4436, there is no significant performance difference between String#match
& RegExp#test
.
Test result & benchmark can be see here: https://github.com/SukkaW/hexo/tree/test-new-yfm-perf |
5946521
to
ca0700f
Compare
@@ -172,7 +166,7 @@ function stringifyJSON(obj) { | |||
} | |||
|
|||
function doubleDigit(num) { | |||
return num < 10 ? `0${num}` : num; | |||
return num.toString().padStart(2, '0'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is from Node.js
's util.
No description provided.