append() was replaced with more efficient copy() (only 1 allocation with make).
This commit is contained in:
parent
978b4c6454
commit
2cf6e1a6cb
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user