unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Gregory Heytings <gregory@heytings.org>
To: "Mattias Engdegård" <mattias.engdegard@gmail.com>
Cc: acohen@ust.hk, 64391@debbugs.gnu.org, eliz@gnu.org,
	monnier@iro.umontreal.ca
Subject: bug#64391: buffer narrowing slowdown regression in emacs 29
Date: Fri, 07 Jul 2023 10:00:48 +0000	[thread overview]
Message-ID: <e642cb1e375be1f23497@heytings.org> (raw)
In-Reply-To: <F61D0758-868C-46E3-B305-CD93A9CE5B43@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 651 bytes --]


Thanks for your feedback!

>
> I have one question about the new `with-restriction` macro: if it is 
> intended as a convenience macro for unlabelled narrowing as well, 
> shouldn't it then expand to the obvious
>
>  (save-restriction
>    (narrow-to-region BEG END)
>    BODY)
>
> instead the much more expensive call to a helper function?
>

Yes.  In fact now that we have a separate function for the labeled case, 
we can remove the funcall in both cases.  Patch attached.

>
> The documentation should also make it clear that `nil` is not a valid 
> label.
>

Is that not already clear in the docstring, which says "in which LABEL is 
a symbol"?

[-- Attachment #2: Simplify-with-restriction-and-without-restriction.patch --]
[-- Type: text/x-diff, Size: 2439 bytes --]

From 4897d6ade80e9928b7f25d0fb6f970c4975c43bd Mon Sep 17 00:00:00 2001
From: Gregory Heytings <gregory@heytings.org>
Date: Fri, 7 Jul 2023 09:54:32 +0000
Subject: [PATCH] Simplify 'with-restriction' and 'without-restriction'

* lisp/subr.el (with-restriction, without-restriction): Merge the
bodies of the 'internal--with-restriction' and
'internal--without-restriction' function into the macros.  The
result is more efficient than a funcall.
(internal--with-restriction, internal--without-restriction):
Remove.
---
 lisp/subr.el | 26 ++++++--------------------
 1 file changed, 6 insertions(+), 20 deletions(-)

diff --git a/lisp/subr.el b/lisp/subr.el
index 85adef5b689..42a6cfec514 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -3973,16 +3973,10 @@ with-restriction
 \(fn START END [:label LABEL] BODY)"
   (declare (indent 2) (debug t))
   (if (eq (car rest) :label)
-      `(internal--with-restriction ,start ,end (lambda () ,@(cddr rest))
-                                 ,(cadr rest))
-    `(internal--with-restriction ,start ,end (lambda () ,@rest))))
-
-(defun internal--with-restriction (start end body &optional label)
-  "Helper function for `with-restriction', which see."
-  (save-restriction
-    (narrow-to-region start end)
-    (if label (internal--label-restriction label))
-    (funcall body)))
+      `(save-restriction
+         (internal--labeled-narrow-to-region ,start ,end ,(cadr rest))
+         ,@(cddr rest))
+    `(save-restriction (narrow-to-region ,start ,end) ,@rest)))
 
 (defmacro without-restriction (&rest rest)
   "Execute BODY without restrictions.
@@ -3996,16 +3990,8 @@ without-restriction
 \(fn [:label LABEL] BODY)"
   (declare (indent 0) (debug t))
   (if (eq (car rest) :label)
-      `(internal--without-restriction (lambda () ,@(cddr rest))
-                                    ,(cadr rest))
-    `(internal--without-restriction (lambda () ,@rest))))
-
-(defun internal--without-restriction (body &optional label)
-  "Helper function for `without-restriction', which see."
-  (save-restriction
-    (if label (internal--unlabel-restriction label))
-    (widen)
-    (funcall body)))
+      `(save-restriction (internal--labeled-widen ,(cadr rest)) ,@(cddr rest))
+    `(save-restriction (widen) ,@rest)))
 
 (defun find-tag-default-bounds ()
   "Determine the boundaries of the default tag, based on text at point.
-- 
2.39.2


  reply	other threads:[~2023-07-07 10:00 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-01  0:15 bug#64391: 30.0.50; buffer narrowing slowdown regression in emacs 29 Andrew Cohen
2023-07-01  2:45 ` bug#64391: bug 64391 wrong git info Andrew Cohen
2023-07-01  4:59 ` bug#64391: more info Andrew Cohen
2023-07-01 11:37   ` bug#64391: buffer narrowing slowdown regression in emacs 29 Mattias Engdegård
2023-07-01 12:08     ` Eli Zaretskii
2023-07-01 12:52       ` Mattias Engdegård
2023-07-02  7:35         ` Gregory Heytings
2023-07-05 11:57           ` Eli Zaretskii
2023-07-06 14:41             ` Gregory Heytings
2023-07-06 17:33               ` Gregory Heytings
2023-07-06 18:22                 ` Eli Zaretskii
2023-07-06 18:45                   ` Gregory Heytings
2023-07-07  9:30                     ` Mattias Engdegård
2023-07-07 10:00                       ` Gregory Heytings [this message]
2023-07-07 10:23                         ` Eli Zaretskii
2023-07-07 10:31                           ` Gregory Heytings
2023-07-07 12:41                             ` Eli Zaretskii
2023-07-07 12:46                               ` Gregory Heytings
2023-07-07 11:33                         ` Mattias Engdegård
2023-07-07 12:42                           ` Gregory Heytings
2023-07-07 15:49                             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-08 20:58                               ` Gregory Heytings
2023-07-08 21:42                                 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-08 22:21                                   ` Gregory Heytings
2023-07-08 23:22                                     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-09 16:03                                       ` Gregory Heytings
2023-07-09 18:57                                         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-09  6:03                                     ` Eli Zaretskii
2023-07-09  8:35                                       ` Gregory Heytings
2023-07-09  8:52                                         ` Eli Zaretskii
2023-07-09 16:04                                           ` Gregory Heytings
2023-07-09 16:39                                             ` Eli Zaretskii
2023-07-09 18:03                                               ` Gregory Heytings
2023-07-09 18:52                                                 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-09 19:19                                                   ` Gregory Heytings
2023-07-09 19:42                                                     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-09 19:44                                                       ` Gregory Heytings
2023-07-09 19:03                                                 ` Eli Zaretskii
2023-07-09 19:06                                                   ` Eli Zaretskii
2023-07-09 19:29                                                     ` Gregory Heytings
2023-07-07 10:27                       ` Eli Zaretskii
2023-07-07 11:27                         ` Mattias Engdegård
2023-07-07 12:50                           ` Eli Zaretskii
2023-07-07 16:49                             ` Mattias Engdegård
2023-07-07 18:22                               ` Eli Zaretskii
2023-07-08  8:01                 ` Eli Zaretskii
2023-07-08 19:41                   ` Gregory Heytings
2023-07-02  9:37         ` Mattias Engdegård
2023-07-01  7:07 ` bug#64391: 30.0.50; " Eli Zaretskii
2023-07-01  7:31   ` Andrew Cohen
2023-07-01  8:09     ` Eli Zaretskii

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=e642cb1e375be1f23497@heytings.org \
    --to=gregory@heytings.org \
    --cc=64391@debbugs.gnu.org \
    --cc=acohen@ust.hk \
    --cc=eliz@gnu.org \
    --cc=mattias.engdegard@gmail.com \
    --cc=monnier@iro.umontreal.ca \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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