Skip to content
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

Merged
merged 2 commits into from Jul 25, 2020

Conversation

SukkaW
Copy link
Member

@SukkaW SukkaW commented Jul 24, 2020

No description provided.

@SukkaW SukkaW requested a review from a team July 24, 2020 14:40
@coveralls
Copy link

coveralls commented Jul 24, 2020

Coverage Status

Coverage remained the same at 100.0% when pulling 5946521 on SukkaW:refactor-regexp into dc1f24d on hexojs:master.

Comment on lines +11 to +23
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);
Copy link
Member Author

@SukkaW SukkaW Jul 24, 2020

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.

@SukkaW
Copy link
Member Author

SukkaW commented Jul 24, 2020

Test result & benchmark can be see here: https://github.com/SukkaW/hexo/tree/test-new-yfm-perf

@SukkaW SukkaW force-pushed the refactor-regexp branch 2 times, most recently from 5946521 to ca0700f Compare July 24, 2020 15:13
@@ -172,7 +166,7 @@ function stringifyJSON(obj) {
}

function doubleDigit(num) {
return num < 10 ? `0${num}` : num;
return num.toString().padStart(2, '0');
Copy link
Member Author

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.

@SukkaW SukkaW mentioned this pull request Jul 24, 2020
@SukkaW SukkaW merged commit 720131d into hexojs:master Jul 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants