Closed 56KBs closed 7 months ago
In principle these changes look like a good idea to me! I haven't looked at the code yet, will get to it in the next few days.
Here are a couple examples of the changes making use of strings.Cut
from Go 1.18+.
authres/parse.go
func parseParam(s string) (k string, v string, err error) {
key, value, ok := strings.Cut(s, "=")
if !ok {
return "", "", errors.New("msgauth: malformed authentication method and value")
}
return strings.TrimSpace(strings.ToLower(key)), strings.TrimSpace(value), nil
}
dkim/verify.go
// Parse algos
keyAlgo, hashAlgo, ok := strings.Cut(stripWhitespace(params["a"]), "-")
if !ok {
return verif, permFailError("malformed algorithm name")
}
These changes would look even more simple through the use of strings.Cut, however this was added in Go 1.18 and I didn't want to force a minimum version bump for the sake of this change (Although 1.18 is now out of support) - If this would be preferred I can do this instead.
I would be completely okay with bumping our minimum required Go version to 1.18.
Code LGTM either way
Improve performance/reduce allocations of within DKIM & Authres with changes:
Replace
strings.SplitN
whereN=2
withstrings.Index
, as this does not complicate the code, but does have the advantage of not needing to allocate a slice of strings with. These changes would look even more simple through the use ofstrings.Cut
, however this was added in Go 1.18 and I didn't want to force a minimum version bump for the sake of this change (Although 1.18 is now out of support) - If this would be preferred I can do this instead.Additional calls to
SplitN
whereN=2
exist in the codebase, but they are in the milter code, or they are in code that has no unit tests so I have not made any changes there.I have replaced the use of a regex to reduce the whitespace within header canonicalization, as regex within Go can be quite slow and given the simplistic nature of the regex it can be easily replaced by using
FieldsFunc
andJoin
.