help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [External] : Passing buffers to function in elisp


From: Stefan Monnier
Subject: Re: [External] : Passing buffers to function in elisp
Date: Tue, 07 Mar 2023 17:45:49 -0500
User-agent: Gnus/5.13 (Gnus v5.13)

>> 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.

> 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.


        Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]