icns

Easily create .icns files (Mac Icons) with this Go library or the included CLI.
Log | Files | Refs | LICENSE

commit c1aa75c9b82939d71eee82fc9ccb83cc20752147
parent cff759cb543a1f59edfad29eba0d57274c35e59b
Author: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Date:   Fri, 18 Sep 2026 16:09:29 -0400

icns: capture loop variables directly in the encoder

The goroutine took copies of its loop variables through parameters, which Go
1.22 made unnecessary when it gave each iteration its own. The inner list also
shadowed the package-level osTypes that sizes the result slice two lines
above it.

Diffstat:
Micns.go | 17+++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/icns.go b/icns.go @@ -68,21 +68,22 @@ func NewIconSet(img image.Image, interp InterpolationFunction) (*IconSet, error) work := sync.WaitGroup{} var iconIdx int for _, size := range sizesFrom(biggest) { - osTypes, ok := getTypesFromSize(size) + types, ok := getTypesFromSize(size) if !ok { continue } - size := size - for _, osType := range osTypes { + for _, osType := range types { work.Add(1) - go func(iconIdx int, osType OsType, size uint) { - icons[iconIdx] = &Icon{ + // iconIdx counts across both loops, so it is passed rather than + // captured; size and osType belong to their iteration. + go func(idx int) { + defer work.Done() + icons[idx] = &Icon{ Type: osType, Image: resizeSquare(img, size, interp), } - work.Done() - }(iconIdx, osType, size) - iconIdx += 1 + }(iconIdx) + iconIdx++ } } work.Wait()