Go

Go

Made by DeepSource

Range over the string directly SCC-SA6003

Performance
Major
Autofix

Loop directly over the runes in a string instead of converting the string to a slice of rune and then looping over the same.

Bad practice

for _, r := range []rune(s) {}

Recommended

for _, r := range s {}

Both bad and recommended practices yield the same values, but the recommended practice will be comparatively faster as it avoids unnecessary memory allocations. If you are interested in the indices, ranging over a string and a slice of rune will yield different indices. The former yields byte offsets, while the latter yields indices in the slice of rune.