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

perf(external_link): faster regexp & condition shorthand #4436

Merged
merged 1 commit into from Jul 24, 2020

Conversation

SukkaW
Copy link
Member

@SukkaW SukkaW commented Jul 24, 2020

What does it do?

  • Improve regexp: require less step for matching
  • Adjust condition for shorthand optimization

How to test

git clone -b perf-external-link https://github.com/sukkaw/hexo.git
cd hexo
npm install
npm test

Screenshots

Pull request tasks

  • Add test cases for the changes.
  • Passed the CI test.

@SukkaW SukkaW requested a review from a team July 24, 2020 08:20
@coveralls
Copy link

Coverage Status

Coverage remained the same at 98.237% when pulling ca1403d on SukkaW:perf-external-link into a34a7e2 on hexojs:master.

data.content = data.content.replace(/<a\s+(?:[^<>]+\s)?href=["']([^<>"']+)["'][^<>]*>/gi, (str, href) => {
if (/target=/gi.test(str) || !isExternalLink(href, url, external_link.exclude)) return str;
data.content = data.content.replace(/<a(?:\s+?|\s+?[^<>]+)?href=["']([^<>"']+)["'][^<>]*>/gi, (str, href) => {
if (!isExternalLink(href, url, external_link.exclude) || /target=/i.test(str)) return str;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most renderer plugin won't add target=. By moving isExternalLink forward unnecessary regex matching could be avoided.

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

Successfully merging this pull request may close these issues.

None yet

3 participants