string
comparison with strings.ToLower
or strings.ToUpper
SCC-SA6005Instead of using strings.ToLower
/strings.ToUpper
with equality check for
string comparison, use strings.EqualFold
directly.
For example:
if strings.ToLower(s1) == strings.ToLower(s2) {
...
}
strings.ToLower
/strings.ToUpper
will have to allocate memory for the new
strings and convert both strings fully, even if they differ on the
first byte. On the other hand, strings.EqualFold
compares the strings one
character at a time. It doesn't need to create two intermediate strings and can
return as soon as the first non-matching character has been found.
return strings.ToLower(s1) == strings.ToLower(s2)
return strings.EqualFold(s1,s2)