all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Michael Heerdegen via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Okamsn <okamsn@protonmail.com>
Cc: 68863@debbugs.gnu.org, Eli Zaretskii <eliz@gnu.org>,
	Nicolas Petton <nicolas@petton.fr>,
	Stefan Monnier <monnier@iro.umontreal.ca>
Subject: bug#68863: Add support for using setf with seq-subseq
Date: Wed, 08 May 2024 23:01:22 +0200	[thread overview]
Message-ID: <87msp0f271.fsf@web.de> (raw)
In-Reply-To: <5db43ef0-f218-4790-b263-a3eb80929d9b@protonmail.com> (okamsn@protonmail.com's message of "Tue, 07 May 2024 01:45:44 +0000")

Okamsn <okamsn@protonmail.com> writes:

> Subject: [PATCH v2] Add setf support for seq-subseq.

Thank you for the update.

I wonder about the implementation for listp STOREs:

> +(cl-defmethod (setf seq-subseq) (store (sequence list) start &optional end)
> +  "Modify the elements of SEQUENCE from START to END to be those of STORE.
> +END is exclusive.
> +
> +If END is omitted, it defaults to the length of the sequence.  If
> +START or END is negative, it counts from the end. [...]

In the case where we don't count from the end:

> +error if START or END are outside of the sequence (i.e too large
> +if positive or too small if negative).
> +
> +SEQUENCE is neither lengthened nor shortened."
> +  (let* ((len (seq-length sequence))

running through the complete list just to get its length which we don't
need is a waste of time - right?

> +      (catch tag
> +        (seq-do (let ((replaced (nthcdr idx sequence)))
> +                  (lambda (v)
> +                    (if (< idx idx-end)
> +                        (setf (car replaced) v
> +                              replaced (cdr replaced)
> +                              idx (1+ idx))
> +                      (throw tag nil))))
> +                store))))
> +  store)

And wouldn't it here be more efficient to use `setcar' and `setcdr'
manipulations to insert the complete sequence (if it's a list, else we
may convert it into one) in one go instead of replacing elements one by
one?


Thanks,

Michael.





  reply	other threads:[~2024-05-08 21:01 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-01  3:31 bug#68863: Add support for using setf with seq-subseq Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-04 18:33 ` bug#68863: [PATCH] " Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-08 11:39 ` bug#68863: " Eli Zaretskii
2024-02-08 14:25   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-09  3:54     ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-14  2:50       ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-18  2:54         ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-07  1:45           ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-08 21:01             ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-05-09 12:16             ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-09 13:55               ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-14 12:47               ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-14 15:52                 ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors

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=87msp0f271.fsf@web.de \
    --to=bug-gnu-emacs@gnu.org \
    --cc=68863@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=michael_heerdegen@web.de \
    --cc=monnier@iro.umontreal.ca \
    --cc=nicolas@petton.fr \
    --cc=okamsn@protonmail.com \
    /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.