unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Matt Armstrong <matt@rfc20.org>
To: Eli Zaretskii <eliz@gnu.org>, Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 59137@debbugs.gnu.org
Subject: bug#59137: [PATCH] To minor changes related to overlays
Date: Tue, 15 Nov 2022 09:53:32 -0800	[thread overview]
Message-ID: <87edu46r4z.fsf@rfc20.org> (raw)
In-Reply-To: <834jv7rt5p.fsf@gnu.org>

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

Eli Zaretskii <eliz@gnu.org> writes:

>> +  if (!node)
>> +    itree_iterator_finish(g);
>                             ^
> Please leave one space between the function's name and the open
> parenthesis of the argument list.

Ahh, yes.  Attached are new patches, rebased to current master, with
that formatting change.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-itree_empty_p-for-clarity-and-reduced-coupling.patch --]
[-- Type: text/x-diff, Size: 2801 bytes --]

From 9cdfe65ee28c68398b9305d15f178358f02f4498 Mon Sep 17 00:00:00 2001
From: Matt Armstrong <matt@rfc20.org>
Date: Tue, 8 Nov 2022 15:00:18 -0800
Subject: [PATCH 1/2] Add itree_empty_p for clarity and reduced coupling

* src/itree.h (itree_empty_p): New predicate.
* src/buffer.h (buffer_has_overlays): Call it.
* src/pdumper.c (dump_buffer): ditto.
* src/alloc.c (mark_buffer): ditto.
---
 src/alloc.c   | 2 +-
 src/buffer.h  | 3 +--
 src/itree.h   | 9 +++++++++
 src/pdumper.c | 2 +-
 4 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/alloc.c b/src/alloc.c
index 6862cf916f..d815a199fe 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -6548,7 +6548,7 @@ mark_buffer (struct buffer *buffer)
   if (!BUFFER_LIVE_P (buffer))
       mark_object (BVAR (buffer, undo_list));
 
-  if (buffer->overlays)
+  if (!itree_empty_p (buffer->overlays))
     mark_overlays (buffer->overlays->root);
 
   /* If this is an indirect buffer, mark its base buffer.  */
diff --git a/src/buffer.h b/src/buffer.h
index 2e80c8a7b0..08b0420c06 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -1273,8 +1273,7 @@ set_buffer_intervals (struct buffer *b, INTERVAL i)
 INLINE bool
 buffer_has_overlays (void)
 {
-  return current_buffer->overlays
-         && (current_buffer->overlays->root != NULL);
+  return !itree_empty_p (current_buffer->overlays);
 }
 \f
 /* Functions for accessing a character or byte,
diff --git a/src/itree.h b/src/itree.h
index 10ee0897c3..d6c6fb1059 100644
--- a/src/itree.h
+++ b/src/itree.h
@@ -25,6 +25,8 @@ #define ITREE_H
 
 #include "lisp.h"
 
+INLINE_HEADER_BEGIN
+
 /* The tree and node structs are mainly here, so they can be
    allocated.
 
@@ -117,6 +119,11 @@ #define ITREE_H
 				   ptrdiff_t, ptrdiff_t);
 extern struct itree_tree *itree_create (void);
 extern void itree_destroy (struct itree_tree *);
+INLINE bool
+itree_empty_p (struct itree_tree *tree)
+{
+  return !tree || !tree->root;
+}
 extern intmax_t itree_size (struct itree_tree *);
 extern void itree_clear (struct itree_tree *);
 extern void itree_insert (struct itree_tree *, struct itree_node *,
@@ -183,4 +190,6 @@ #define ITREE_FOREACH_ABORT() \
 #define ITREE_FOREACH_NARROW(beg, end) \
   itree_iterator_narrow (itree_iter_, beg, end)
 
+INLINE_HEADER_END
+
 #endif
diff --git a/src/pdumper.c b/src/pdumper.c
index 0a5d96dbb7..22d3f3f90e 100644
--- a/src/pdumper.c
+++ b/src/pdumper.c
@@ -2863,7 +2863,7 @@ dump_buffer (struct dump_context *ctx, const struct buffer *in_buffer)
   DUMP_FIELD_COPY (out, buffer, inhibit_buffer_hooks);
   DUMP_FIELD_COPY (out, buffer, long_line_optimizations_p);
 
-  if (buffer->overlays && buffer->overlays->root != NULL)
+  if (!itree_empty_p (buffer->overlays))
     /* We haven't implemented the code to dump overlays.  */
     emacs_abort ();
   else
-- 
2.35.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-Simplify-ITREE_FOREACH.patch --]
[-- Type: text/x-diff, Size: 1795 bytes --]

From c2fc83ff7e7d49bdb013881453e504f21f038104 Mon Sep 17 00:00:00 2001
From: Matt Armstrong <matt@rfc20.org>
Date: Tue, 8 Nov 2022 15:08:00 -0800
Subject: [PATCH 2/2] Simplify ITREE_FOREACH

* src/itree.c (itree_iterator_next): Call itree_iterator_finish if
returning NULL.
* src/itree.h (ITREE_FOREACH): Don't call itree_iterator_finish.
---
 src/itree.c | 3 +++
 src/itree.h | 7 +++----
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/itree.c b/src/itree.c
index ae69c97d6d..18ee6449ce 100644
--- a/src/itree.c
+++ b/src/itree.c
@@ -1431,6 +1431,9 @@ itree_iterator_next (struct itree_iterator *g)
 	 after it was pushed: Check if it still intersects. */
     } while (node && ! interval_node_intersects (node, g->begin, g->end));
 
+  if (!node)
+    itree_iterator_finish (g);
+
   return node;
 }
 
diff --git a/src/itree.h b/src/itree.h
index d6c6fb1059..67e258dd83 100644
--- a/src/itree.h
+++ b/src/itree.h
@@ -179,10 +179,9 @@ #define ITREE_FOREACH(n, t, beg, end, order)                        \
     { }                                                             \
   else                                                              \
     for (struct itree_iterator *itree_iter_                         \
-            = itree_iterator_start (t, beg, end, ITREE_##order,     \
-                                        __FILE__, __LINE__);        \
-          ((n = itree_iterator_next (itree_iter_))                  \
-           || (itree_iterator_finish (itree_iter_), false));)
+           = itree_iterator_start (t, beg, end, ITREE_##order,      \
+                                   __FILE__, __LINE__);             \
+         (n = itree_iterator_next (itree_iter_));)
 
 #define ITREE_FOREACH_ABORT() \
   itree_iterator_finish (itree_iter_)
-- 
2.35.1


  reply	other threads:[~2022-11-15 17:53 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-08 23:14 bug#59137: [PATCH] To minor changes related to overlays Matt Armstrong
2022-11-10 10:38 ` Eli Zaretskii
2022-11-15 17:53   ` Matt Armstrong [this message]
2022-11-25  1:16     ` Stefan Kangas
2022-11-25 14:48       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-26 14:05         ` Stefan Kangas
2022-11-26 19:37           ` Matt Armstrong
2022-11-26 20:07             ` Stefan Kangas
2022-11-29 23:16               ` Matt Armstrong
2022-11-30  1:28                 ` Stefan Kangas
2022-11-30 13:25                   ` Eli Zaretskii
2022-11-30 17:34                     ` Stefan Kangas

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=87edu46r4z.fsf@rfc20.org \
    --to=matt@rfc20.org \
    --cc=59137@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --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).