Skip to content

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?

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