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

chore: Use slices package where possible #6585

Merged
merged 3 commits into from
Sep 25, 2024
Merged

chore: Use slices package where possible #6585

merged 3 commits into from
Sep 25, 2024

Conversation

francislavoie
Copy link
Member

Just a simple cleanup, we can use slices.Contains() in a bunch of spots now instead of helper functions to do the simple loop.

@francislavoie
Copy link
Member Author

2nd commit is potentially more controversial, using ContainsFunc (5 lines -> 3 lines).

Copy link
Member

@mohammed90 mohammed90 left a comment

Choose a reason for hiding this comment

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

I like it, even the controversial one!

@francislavoie
Copy link
Member Author

Added even more.

FWIW, I was using regexp searches like this to find them 😂 might've missed some, did the ones I could find.

	*for [a-zA-Z_\.]*, [a-zA-Z_\.]* := range [a-zA-Z_\.]* \{
	*if [a-zA-Z_\.]* == [a-zA-Z_\.]* \{

@francislavoie francislavoie force-pushed the slices-pkg branch 2 times, most recently from 9151be6 to 610980c Compare September 23, 2024 06:55
@mohammed90
Copy link
Member

FWIW, I was using regexp searches like this to find them 😂 might've missed some, did the ones I could find.

	*for [a-zA-Z_\.]*, [a-zA-Z_\.]* := range [a-zA-Z_\.]* \{
	*if [a-zA-Z_\.]* == [a-zA-Z_\.]* \{

I was going to suggest semgrep, but apparently they went all proprietary 😕

Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

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

Finally got through all 21 files. I think they are correct changes, if I understand the functions correctly. Thank you for the improvements!

@@ -110,17 +111,12 @@ func parseOptOrder(d *caddyfile.Dispenser, _ any) (any, error) {
}
pos := Positional(d.Val())

newOrder := directiveOrder
// if directive already had an order, drop it
newOrder := slices.DeleteFunc(directiveOrder, func(d string) bool {
Copy link
Member

Choose a reason for hiding this comment

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

Woah, this is nice.

Comment on lines +292 to +294
optsIndex := slices.IndexFunc(serverOpts, func(s serverOptions) bool {
return s.ListenerAddress == "" || slices.Contains(server.Listen, s.ListenerAddress)
})
Copy link
Member

Choose a reason for hiding this comment

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

Wow, big win here.

@mholt mholt merged commit 2faeac0 into master Sep 25, 2024
33 checks passed
@mholt mholt deleted the slices-pkg branch September 25, 2024 20:30
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.

3 participants