Optimize rand_candidate

The set of searchable songs shouldn't change while selecting songs.  We
can determine which list of songs to look at up front and always use
that as an argument to rand_candidate()
This commit is contained in:
Bryan Schumaker 2010-11-14 19:32:47 -05:00
parent 654cd9c418
commit 38026a43c5
1 changed files with 9 additions and 5 deletions

View File

@ -77,19 +77,23 @@ def seq_next():
cur_index += 1
return song_list[cur_index]
def rand_candidate(max):
def rand_candidate(list, max):
index = rand.randint(0, max-1)
if filtered == False:
return song_list[index]
return list(visible)[index]
return list[index]
def rand_next():
n = num_visible()
if n == 0:
return
get_attrs = library.get_attrs
if filtered == False:
selection = song_list
else:
selection = list(visible)
for i in xrange(15):
id = rand_candidate(n)
id = rand_candidate(selection, n)
(artist, title, score) = get_attrs(id, "artist", "title", "score")
if (artist, title) in recent:
print recent_msg % (artist, title)