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

Reduce regular expression compilation #158

Merged
merged 1 commit into from
Aug 29, 2016
Merged

Reduce regular expression compilation #158

merged 1 commit into from
Aug 29, 2016

Conversation

itchyny
Copy link
Contributor

@itchyny itchyny commented Aug 24, 2016

Hi, I've started reading the code of vuls yesterday and noticed the many regexp compilation on runtime. Specifically, we should avoid calling regexp.Compile in loops because it affects the performance badly. What do you think?

@itchyny
Copy link
Contributor Author

itchyny commented Aug 26, 2016

Basically all the regular expressions should be compiled at the top level, outside the functions for consistency. I agree with the opinion but it can lead to lower readability, more initialisation when you support many platforms. But if you don't mind it, I'll move them all.

@kotakanbe
Copy link
Member

Thanks for sending P/R :)

I agree with the opinion but it can lead to lower readability,

Readability is more important than performance for Vuls.
So, I am going to merge your P/R.

Would you merge in only one commit?

- use regexp.MustCompile instead of regexp.Compile
- use strings.HasPrefix instead of regular expression when it is enough
@itchyny
Copy link
Contributor Author

itchyny commented Aug 26, 2016

Okay. I've squashed the commits.

@kotakanbe kotakanbe merged commit 5959235 into future-architect:master Aug 29, 2016
@kotakanbe
Copy link
Member

Many Thanks :)

@itchyny itchyny deleted the regexp-must-compile branch August 30, 2016 00:31
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.

2 participants