[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [External] : Passing buffers to function in elisp
From: |
tomas |
Subject: |
Re: [External] : Passing buffers to function in elisp |
Date: |
Wed, 8 Mar 2023 06:38:54 +0100 |
On Tue, Mar 07, 2023 at 05:45:49PM -0500, Stefan Monnier wrote:
> >> This is a typical a source of unnecessary O(N²) complexity: the above
> >> line takes O(N) time, so if you do it O(N) times, you got your
> >> N² blowup. You're usually better off doing
> >>
> >> (push (plist-get page :stream) stream-chunks)
> >>
> >> and then at the end get the `stream` with
> >>
> >> (mapconcat #'identity (nreverse stream-chunks) nil)
> >> or
> >> (apply #'vconcat (nreverse stream-chunks))
> >
> > Right, I see. Stream chunks are in this case byte vectors, so
> > just reversing those chunks does not do the trick.
> > But surely I can get from an order of N² to 2N or so.
>
> I'm suggesting to build a list of chunks backward and to reverse *the
> list*, not the chunks. So the end result should still be the same.
Judging by the "2N instead of N^2" I guess Petteri had the right
mental model, though.
> > Okay, this is something I did not foresee. But what about eval-defun
> > and eval-... in general? They are very convenient when trying out
> > things.
>
> It's OK to use them, of course. It usually means you still have 98% of
> your code compiled.
>
> >> The compiler is your friend. He can help you get the code in good
> >> shape :-)
> > I'm afraid that even the compiler cannot help against quadratic
> > complexity blunders.
>
> :-)
>
> It's just a friend, yes.
:-)
Cheers
--
t
signature.asc
Description: PGP signature