Skip to content

Bump minimum Go to 1.22 and use new features#1017

Merged
VojtechVitek merged 1 commit intogo-chi:masterfrom
JRaspass:master
Sep 17, 2025
Merged

Bump minimum Go to 1.22 and use new features#1017
VojtechVitek merged 1 commit intogo-chi:masterfrom
JRaspass:master

Conversation

@JRaspass
Copy link
Contributor

Go 1.21 brings us the builtin min func and slices.Contains.

Go 1.22 brings us range over int and fixed for loop scoping.

We were also able to drop the build tags from the path value code and inline the three-line function directly. This should still work on tinygo as they claim to support Go 1.24.

Go 1.21 brings us the builtin min func and slices.Contains.

Go 1.22 brings us range over int and fixed for loop scoping.

We were also able to drop the build tags from the path value code and
inline the three-line function directly. This should still work on
tinygo as they claim to support Go 1.24.
@VojtechVitek VojtechVitek changed the title Bump minimum Go and use new features Bump minimum Go to 1.22 and use new features Aug 26, 2025
Copy link
Contributor

@VojtechVitek VojtechVitek left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you!

I'll wait for more 👀 to review and then we can merge. 👍

// longestPrefix finds the length of the shared prefix
// of two strings
func longestPrefix(k1, k2 string) int {
max := len(k1)
Copy link
Contributor

Choose a reason for hiding this comment

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

interesting .. so this variable was named incorrectly - it meant "min" instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I think the original naming was meant to imply max iterations as opposed to min string length. But I agree it was a little confusing.

Comment on lines +773 to +780
// longestPrefix finds the length of the shared prefix of two strings
func longestPrefix(k1, k2 string) (i int) {
for i = 0; i < min(len(k1), len(k2)); i++ {
if k1[i] != k2[i] {
break
}
}
return i
return
Copy link
Contributor

@VojtechVitek VojtechVitek Aug 26, 2025

Choose a reason for hiding this comment

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

This looks good

Copy link
Contributor

@VojtechVitek VojtechVitek Aug 26, 2025

Choose a reason for hiding this comment

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

One thing I noticed -- (unrelated to this PR) -- this function might not work well with unicode characters, as it works on bytes and not on runes.

The question is -- are we ever passing unicode strings into this function (e.g. "/café", "/café/1"). Can this happen?

@benstigsen
Copy link

LGTM

@VojtechVitek VojtechVitek merged commit a52c582 into go-chi:master Sep 17, 2025
8 checks passed
JRaspass added a commit to JRaspass/chi that referenced this pull request Oct 9, 2025
This wasn't updated in either go-chi#969 or go-chi#1017 and is the first thing people read on pkg.go.dev.
JRaspass added a commit to JRaspass/chi that referenced this pull request Oct 9, 2025
This wasn't updated in either go-chi#969 or go-chi#1017 and is the first thing people read on pkg.go.dev.
VojtechVitek pushed a commit that referenced this pull request Oct 9, 2025
This wasn't updated in either #969 or #1017 and is the first thing people read on pkg.go.dev.
wwqgtxx added a commit to MetaCubeX/chi that referenced this pull request Dec 17, 2025
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