unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Marcin Borkowski <mbork@mbork.pl>
To: Michael Heerdegen <michael_heerdegen@web.de>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Passing buffers to function in elisp
Date: Thu, 23 Feb 2023 17:19:37 +0100	[thread overview]
Message-ID: <87r0ugcq1y.fsf@mbork.pl> (raw)
In-Reply-To: <87k008lo7r.fsf@web.de>


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



      parent reply	other threads:[~2023-02-23 16:19 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-21 21:18 Passing buffers to function in elisp Petteri Hintsanen
2023-02-21 23:21 ` [External] : " Drew Adams
2023-02-22  5:35   ` tomas
2023-02-24 20:08     ` Petteri Hintsanen
2023-02-25  6:40       ` tomas
2023-02-25 11:23       ` Michael Heerdegen
2023-02-25 13:45         ` tomas
2023-02-25 18:31           ` Michael Heerdegen
2023-02-25 19:05             ` tomas
2023-02-25 23:52         ` Stefan Monnier via Users list for the GNU Emacs text editor
2023-02-27 20:44           ` Petteri Hintsanen
2023-02-28  5:37             ` tomas
2023-03-03 15:19             ` Stefan Monnier via Users list for the GNU Emacs text editor
2023-03-07 21:48               ` Petteri Hintsanen
2023-03-07 22:45                 ` Stefan Monnier
2023-03-08  5:38                   ` tomas
2023-09-06 19:05               ` Petteri Hintsanen
2023-09-06 21:12                 ` Stefan Monnier
2023-02-22  5:30 ` tomas
2023-02-23  9:34   ` Michael Heerdegen
2023-02-23  9:51     ` tomas
2023-02-23 16:19     ` Marcin Borkowski [this message]

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=87r0ugcq1y.fsf@mbork.pl \
    --to=mbork@mbork.pl \
    --cc=help-gnu-emacs@gnu.org \
    --cc=michael_heerdegen@web.de \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).