commit 0438531d4191fa06d4c1174ee2eaa194e7692fdf
parent 4dbe1cc82123fc38af868c5d65e4fec1b626637c
Author: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Date: Fri, 18 Sep 2026 16:09:30 -0400
icns: size the icon set from the types it will write
The result slice was sized by the whole type table, so any size the source
could not fill left a nil hole for the writer to skip, and a running index
had to be threaded through the goroutines. Building the list first makes the
slice exact.
Diffstat:
| M | icns.go | | | 30 | ++++++++++++++---------------- |
1 file changed, 14 insertions(+), 16 deletions(-)
diff --git a/icns.go b/icns.go
@@ -64,27 +64,25 @@ func NewIconSet(img image.Image, interp InterpolationFunction) (*IconSet, error)
if biggest == 0 {
return nil, ErrImageTooSmall{image: img, need: 16}
}
- icons := make([]*Icon, len(osTypes))
- work := sync.WaitGroup{}
- var iconIdx int
+ var plan []OsType
for _, size := range sizesFrom(biggest) {
types, ok := getTypesFromSize(size)
if !ok {
continue
}
- for _, osType := range types {
- work.Add(1)
- // 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),
- }
- }(iconIdx)
- iconIdx++
- }
+ plan = append(plan, types...)
+ }
+ icons := make([]*Icon, len(plan))
+ work := sync.WaitGroup{}
+ for i, osType := range plan {
+ work.Add(1)
+ go func() {
+ defer work.Done()
+ icons[i] = &Icon{
+ Type: osType,
+ Image: resizeSquare(img, osType.Size, interp),
+ }
+ }()
}
work.Wait()
iconSet := &IconSet{