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

Recommend replacing rx.FindIndex(b) != nil with rx.Match(b) #1518

Open
kevinburkesegment opened this issue Apr 11, 2024 · 2 comments
Open

Recommend replacing rx.FindIndex(b) != nil with rx.Match(b) #1518

kevinburkesegment opened this issue Apr 11, 2024 · 2 comments

Comments

@kevinburkesegment
Copy link

I was just looking at some code that compiled a regex, and then checked for a match by writing:

rx := regexp.MustCompile(/* ... */)
return rx.FindIndex(b) != nil 

This is reducible to return rx.Match(b), which is less wasteful. It would be good to suggest this optimization.

@kevinburkesegment kevinburkesegment added the needs-triage Newly filed issue that needs triage label Apr 11, 2024
@dominikh dominikh added enhancement and removed needs-triage Newly filed issue that needs triage labels Apr 12, 2024
@dominikh dominikh changed the title detect and warn on unnecessary regexp compilation Recommend replacing rx.FindIndex(b) != nil with rx.Match(b) Apr 12, 2024
@dominikh
Copy link
Owner

I've retitled the issue to more closely match what I think your intention is.

@kevinburkesegment
Copy link
Author

kevinburkesegment commented Apr 12, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants