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

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

Re: Passing buffers to function in elisp


From: Marcin Borkowski
Subject: Re: Passing buffers to function in elisp
Date: Thu, 23 Feb 2023 17:19:37 +0100
User-agent: mu4e 1.1.0; emacs 30.0.50

On 2023-02-23, at 10:34, Michael Heerdegen <michael_heerdegen@web.de> wrote:

> <tomas@tuxteam.de> writes:
>
>> > Is it better just to assume in functions that the current buffer is
>> > the data buffer and work on that, instead of passing data as
>> > function arguments?
>>
>> That depends on your style and on the "contracts" you make
>> with yourself (and ultimately, of course, on what you are
>> trying to do: for each different purpose, some style will
>> be clearer/more efficient -- ideally both, but life and
>> things).
>
> And there is not only garbage, there is also the aspect of speed: many
> operations can be performed in buffers and likewise for strings, but
> sometimes operations are a lot faster for strings (modifying a buffer is
> a more complicated operation).

Well, I am fairly sure there are things which are faster for buffers,
too...  A few years ago I did some experimenting with that:
https://mbork.pl/2019-03-25_Using_benchmark_to_measure_speed_of_Elisp_code

As for testing with buffers, you might be interested in the
`elisp-tests-with-temp-buffer' macro I've written a long time ago (see
emacs/test/lisp/emacs-lisp/lisp-tests.el:317).

The bottom line is probably this: do whatever you prefer, and optimize
when it's needed (as Tomas said).

Hth,

-- 
Marcin Borkowski
http://mbork.pl



reply via email to

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