From aeee5518ac9c96c2728dd24291142da21c03a307 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Tue, 27 Dec 2011 23:57:03 +0100 Subject: [PATCH] Improved and simplified the 'playlistinfo' command handler Cleaning up the rest of the code, it became obvious that sandos' performance patch did not alter the semantics of 'playlistinfo'. --- .../mpd/protocol/current_playlist.py | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/mopidy/frontends/mpd/protocol/current_playlist.py b/mopidy/frontends/mpd/protocol/current_playlist.py index c566bf7e..14816024 100644 --- a/mopidy/frontends/mpd/protocol/current_playlist.py +++ b/mopidy/frontends/mpd/protocol/current_playlist.py @@ -255,32 +255,26 @@ def playlistinfo(context, songpos=None, if start == -1: end = None else: - #Fetch one single track, hot code path (avoid deep-copying the entire playlist) - res = context.backend.current_playlist.get(cpid=songpos).get() - cpids = [res.cpid] - l = [res.track] - return tracks_to_mpd_format(l, 0, 1, cpids=cpids) - cpids = [ct[0] for ct in - context.backend.current_playlist.cp_tracks.get()] - return tracks_to_mpd_format( - context.backend.current_playlist.tracks.get(), - start, end, cpids=cpids) + # Hot code path: Fetch a single track, while avoiding deep-copying + # the entire playlist + cp_track = context.backend.current_playlist.get(cpid=songpos).get() + cpids = [cp_track.cpid] + tracks = [cp_track.track] + return tracks_to_mpd_format(tracks, 0, 1, cpids=cpids) else: if start is None: start = 0 start = int(start) - if not (0 <= start <= len( - context.backend.current_playlist.tracks.get())): + if not (0 <= start <= context.backend.current_playlist.length.get()): raise MpdArgError(u'Bad song index', command=u'playlistinfo') if end is not None: end = int(end) - if end > len(context.backend.current_playlist.tracks.get()): + if end > context.backend.current_playlist.length.get(): end = None - cpids = [ct[0] for ct in - context.backend.current_playlist.cp_tracks.get()] - return tracks_to_mpd_format( - context.backend.current_playlist.tracks.get(), - start, end, cpids=cpids) + cp_tracks = context.backend.current_playlist.cp_tracks.get() + cpids = [cp_track.cpid for cp_track in cp_tracks] + tracks = [cp_track.track for cp_track in cp_tracks] + return tracks_to_mpd_format(tracks, start, end, cpids=cpids) @handle_request(r'^playlistsearch "(?P[^"]+)" "(?P[^"]+)"$') @handle_request(r'^playlistsearch (?P\S+) "(?P[^"]+)"$')