From 2cf6e1a6cb199be8c954eb8aab789b3f2c5062fb Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Thu, 14 Sep 2023 18:20:47 +0400 Subject: [PATCH] append() was replaced with more efficient copy() (only 1 allocation with make). --- internal/radio/icecast.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/radio/icecast.go b/internal/radio/icecast.go index 05aabe8..88cd322 100644 --- a/internal/radio/icecast.go +++ b/internal/radio/icecast.go @@ -80,8 +80,8 @@ func IcecastLastSongs(playlistPath string) []Song { lastPlayedCacheMutex.Lock() defer lastPlayedCacheMutex.Unlock() if lpcLen := len(lastPlayedCache); lpcLen > 0 { - ret := make([]Song, 0, lpcLen) - ret = append(ret, lastPlayedCache...) + ret := make([]Song, lpcLen) + copy(ret, lastPlayedCache) return ret } @@ -181,10 +181,10 @@ func (pw *PlaylistLogWatcher) Watch(playlistPath string, n int) (err error) { pw.watcher.WatchForMask(pw.changed, watcher.ModIgnMask) if lastPlayedCache == nil { - lastPlayedCache = make([]Song, 0, n) + lastPlayedCache = make([]Song, n) songs, err := icecastLastPlayedSongs(playlistPath, n) if err == nil && len(songs) > 0 { - lastPlayedCache = append(lastPlayedCache, songs...) + copy(lastPlayedCache, songs) } else if err != nil { log.Fatalln("failed to retrieve last songs:", err) }