[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [elpa] externals/emms e9fa4c095d: * emms.el: reverse the order playe
From: |
Yoni Rabkin |
Subject: |
Re: [elpa] externals/emms e9fa4c095d: * emms.el: reverse the order players are collected |
Date: |
Wed, 07 Sep 2022 16:16:00 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.1 (gnu/linux) |
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> --- a/emms.el
>> +++ b/emms.el
>> @@ -1511,7 +1511,7 @@ If the track can be played by more than one player,
>> call
>> (mapc
>> #'(lambda (player)
>> (when (funcall (emms-player-get player 'playablep) track)
>> - (push player players)))
>> + (setq players (append players `(,player)))))
>> emms-player-list)
>> (if (< 1 (length players))
>> (emms-players-preference track players)
>
> This changes the code's complexity from O(N) to O(N²) in the number of
> players.
Is this because append has to traverse the list all of the way to the
last cdr every time?
> Maybe it's not a very big deal,
Indeed. Since the list of players is a constant (about 7), this ends up
being constant-time. I tend to ignore how short lists are processed, and
I indeed didn't think about big-O of anything when I made this change.
> but the standard way to avoid this is to use `push` inside the loop
> followed by `nreverse` at the of the loop.
Doing it the Right Way (TM) feels better regardless of if it makes any
actual sense(*). Programming is about elegance as much as anything
else. I'll change it to use push and nreverse.
* We've probably spent more time in this conversation than the sum total
processing time of all of the machines which will ever run this code.
--
"Cut your own wood and it will warm you twice"