all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Yoni Rabkin <yoni@rabkins.net>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: [elpa] externals/emms e9fa4c095d: * emms.el: reverse the order players are collected
Date: Wed, 07 Sep 2022 16:16:00 -0400	[thread overview]
Message-ID: <87illzym7z.fsf@rabkins.net> (raw)
In-Reply-To: <jwv7d2gosxr.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Tue, 06 Sep 2022 21:50:40 -0400")

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"



  reply	other threads:[~2022-09-07 20:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <166250171605.12534.6807904164286037648@vcs2.savannah.gnu.org>
     [not found] ` <20220906220156.5255DC0088A@vcs2.savannah.gnu.org>
2022-09-07  1:50   ` [elpa] externals/emms e9fa4c095d: * emms.el: reverse the order players are collected Stefan Monnier
2022-09-07 20:16     ` Yoni Rabkin [this message]
2022-09-07 20:26       ` Stefan Monnier
2022-09-08  4:26         ` tomas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87illzym7z.fsf@rabkins.net \
    --to=yoni@rabkins.net \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.