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()
|
lastPlayedCacheMutex.Lock()
|
||||||
defer lastPlayedCacheMutex.Unlock()
|
defer lastPlayedCacheMutex.Unlock()
|
||||||
if lpcLen := len(lastPlayedCache); lpcLen > 0 {
|
if lpcLen := len(lastPlayedCache); lpcLen > 0 {
|
||||||
ret := make([]Song, 0, lpcLen)
|
ret := make([]Song, lpcLen)
|
||||||
ret = append(ret, lastPlayedCache...)
|
copy(ret, lastPlayedCache)
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,10 +181,10 @@ func (pw *PlaylistLogWatcher) Watch(playlistPath string, n int) (err error) {
|
|||||||
pw.watcher.WatchForMask(pw.changed, watcher.ModIgnMask)
|
pw.watcher.WatchForMask(pw.changed, watcher.ModIgnMask)
|
||||||
|
|
||||||
if lastPlayedCache == nil {
|
if lastPlayedCache == nil {
|
||||||
lastPlayedCache = make([]Song, 0, n)
|
lastPlayedCache = make([]Song, n)
|
||||||
songs, err := icecastLastPlayedSongs(playlistPath, n)
|
songs, err := icecastLastPlayedSongs(playlistPath, n)
|
||||||
if err == nil && len(songs) > 0 {
|
if err == nil && len(songs) > 0 {
|
||||||
lastPlayedCache = append(lastPlayedCache, songs...)
|
copy(lastPlayedCache, songs)
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
log.Fatalln("failed to retrieve last songs:", err)
|
log.Fatalln("failed to retrieve last songs:", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user