emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r109155: New macro to iterate over al


From: Dmitry Antipov
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r109155: New macro to iterate over all buffers, miscellaneous cleanups.
Date: Thu, 19 Jul 2012 07:55:59 +0400
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 109155
committer: Dmitry Antipov <address@hidden>
branch nick: trunk
timestamp: Thu 2012-07-19 07:55:59 +0400
message:
  New macro to iterate over all buffers, miscellaneous cleanups.
  * lisp.h (all_buffers): Remove declaration.
  * buffer.h (all_buffers): Add declaration, with comment.
  (for_each_buffer): New macro.
  * alloc.c (Fgarbage_collect, mark_object): Use it.
  * buffer.c (Fkill_buffer, Fbuffer_swap_text, Fset_buffer_multibyte)
  (init_buffer): Likewise.
  * data.c (Fset_default): Likewise.
  * coding.c (code_conversion_restore): Remove redundant check
  for dead buffer.
  * buffer.c (Fkill_buffer): Likewise.  Remove obsolete comment.
modified:
  src/ChangeLog
  src/alloc.c
  src/buffer.c
  src/buffer.h
  src/coding.c
  src/data.c
  src/lisp.h
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2012-07-18 21:33:37 +0000
+++ b/src/ChangeLog     2012-07-19 03:55:59 +0000
@@ -1,3 +1,17 @@
+2012-07-19  Dmitry Antipov  <address@hidden>
+
+       New macro to iterate over all buffers, miscellaneous cleanups.
+       * lisp.h (all_buffers): Remove declaration.
+       * buffer.h (all_buffers): Add declaration, with comment.
+       (for_each_buffer): New macro.
+       * alloc.c (Fgarbage_collect, mark_object): Use it.
+       * buffer.c (Fkill_buffer, Fbuffer_swap_text, Fset_buffer_multibyte)
+       (init_buffer): Likewise.
+       * data.c (Fset_default): Likewise.
+       * coding.c (code_conversion_restore): Remove redundant check
+       for dead buffer.
+       * buffer.c (Fkill_buffer): Likewise.  Remove obsolete comment.
+
 2012-07-18  Andreas Schwab  <address@hidden>
 
        Fix bug that created negative-length intervals.
@@ -110,7 +124,6 @@
        * gnutls.c (emacs_gnutls_handshake): Only retry if
        GNUTLS_E_INTERRUPTED.
 
-2012-07-17  Eli Zaretskii  <address@hidden>
 2012-07-17  Dmitry Antipov  <address@hidden>
 
        Cleanup and convert miscellaneous checks to eassert.

=== modified file 'src/alloc.c'
--- a/src/alloc.c       2012-07-18 17:29:34 +0000
+++ b/src/alloc.c       2012-07-19 03:55:59 +0000
@@ -5392,6 +5392,7 @@
   (void)
 {
   register struct specbinding *bind;
+  register struct buffer *nextb;
   char stack_top_variable;
   ptrdiff_t i;
   int message_p;
@@ -5411,40 +5412,34 @@
 
   /* Don't keep undo information around forever.
      Do this early on, so it is no problem if the user quits.  */
-  {
-    register struct buffer *nextb = all_buffers;
-
-    while (nextb)
-      {
-       /* If a buffer's undo list is Qt, that means that undo is
-          turned off in that buffer.  Calling truncate_undo_list on
-          Qt tends to return NULL, which effectively turns undo back on.
-          So don't call truncate_undo_list if undo_list is Qt.  */
-       if (! NILP (nextb->BUFFER_INTERNAL_FIELD (name))
-           && ! EQ (nextb->BUFFER_INTERNAL_FIELD (undo_list), Qt))
-         truncate_undo_list (nextb);
-
-       /* Shrink buffer gaps, but skip indirect and dead buffers.  */
-       if (nextb->base_buffer == 0 && !NILP (nextb->BUFFER_INTERNAL_FIELD 
(name))
-           && ! nextb->text->inhibit_shrinking)
-         {
-           /* If a buffer's gap size is more than 10% of the buffer
-              size, or larger than 2000 bytes, then shrink it
-              accordingly.  Keep a minimum size of 20 bytes.  */
-           int size = min (2000, max (20, (nextb->text->z_byte / 10)));
-
-           if (nextb->text->gap_size > size)
-             {
-               struct buffer *save_current = current_buffer;
-               current_buffer = nextb;
-               make_gap (-(nextb->text->gap_size - size));
-               current_buffer = save_current;
-             }
-         }
-
-       nextb = nextb->header.next.buffer;
-      }
-  }
+  for_each_buffer (nextb)
+    {
+      /* If a buffer's undo list is Qt, that means that undo is
+        turned off in that buffer.  Calling truncate_undo_list on
+        Qt tends to return NULL, which effectively turns undo back on.
+        So don't call truncate_undo_list if undo_list is Qt.  */
+      if (! NILP (nextb->BUFFER_INTERNAL_FIELD (name))
+         && ! EQ (nextb->BUFFER_INTERNAL_FIELD (undo_list), Qt))
+       truncate_undo_list (nextb);
+
+      /* Shrink buffer gaps, but skip indirect and dead buffers.  */
+      if (nextb->base_buffer == 0 && !NILP (nextb->BUFFER_INTERNAL_FIELD 
(name))
+         && ! nextb->text->inhibit_shrinking)
+       {
+         /* If a buffer's gap size is more than 10% of the buffer
+            size, or larger than 2000 bytes, then shrink it
+            accordingly.  Keep a minimum size of 20 bytes.  */
+         int size = min (2000, max (20, (nextb->text->z_byte / 10)));
+
+         if (nextb->text->gap_size > size)
+           {
+             struct buffer *save_current = current_buffer;
+             current_buffer = nextb;
+             make_gap (-(nextb->text->gap_size - size));
+             current_buffer = save_current;
+           }
+       }
+    }
 
   t1 = current_emacs_time ();
 
@@ -5558,48 +5553,42 @@
      Look thru every buffer's undo list
      for elements that update markers that were not marked,
      and delete them.  */
-  {
-    register struct buffer *nextb = all_buffers;
-
-    while (nextb)
-      {
-       /* If a buffer's undo list is Qt, that means that undo is
-          turned off in that buffer.  Calling truncate_undo_list on
-          Qt tends to return NULL, which effectively turns undo back on.
-          So don't call truncate_undo_list if undo_list is Qt.  */
-       if (! EQ (nextb->BUFFER_INTERNAL_FIELD (undo_list), Qt))
-         {
-           Lisp_Object tail, prev;
-           tail = nextb->BUFFER_INTERNAL_FIELD (undo_list);
-           prev = Qnil;
-           while (CONSP (tail))
-             {
-               if (CONSP (XCAR (tail))
-                   && MARKERP (XCAR (XCAR (tail)))
-                   && !XMARKER (XCAR (XCAR (tail)))->gcmarkbit)
-                 {
-                   if (NILP (prev))
-                     nextb->BUFFER_INTERNAL_FIELD (undo_list) = tail = XCDR 
(tail);
-                   else
-                     {
-                       tail = XCDR (tail);
-                       XSETCDR (prev, tail);
-                     }
-                 }
-               else
-                 {
-                   prev = tail;
-                   tail = XCDR (tail);
-                 }
-             }
-         }
-       /* Now that we have stripped the elements that need not be in the
-          undo_list any more, we can finally mark the list.  */
-       mark_object (nextb->BUFFER_INTERNAL_FIELD (undo_list));
-
-       nextb = nextb->header.next.buffer;
-      }
-  }
+  for_each_buffer (nextb)
+    {
+      /* If a buffer's undo list is Qt, that means that undo is
+        turned off in that buffer.  Calling truncate_undo_list on
+        Qt tends to return NULL, which effectively turns undo back on.
+        So don't call truncate_undo_list if undo_list is Qt.  */
+      if (! EQ (nextb->BUFFER_INTERNAL_FIELD (undo_list), Qt))
+       {
+         Lisp_Object tail, prev;
+         tail = nextb->BUFFER_INTERNAL_FIELD (undo_list);
+         prev = Qnil;
+         while (CONSP (tail))
+           {
+             if (CONSP (XCAR (tail))
+                 && MARKERP (XCAR (XCAR (tail)))
+                 && !XMARKER (XCAR (XCAR (tail)))->gcmarkbit)
+               {
+                 if (NILP (prev))
+                   nextb->BUFFER_INTERNAL_FIELD (undo_list) = tail = XCDR 
(tail);
+                 else
+                   {
+                     tail = XCDR (tail);
+                     XSETCDR (prev, tail);
+                   }
+               }
+             else
+               {
+                 prev = tail;
+                 tail = XCDR (tail);
+               }
+           }
+       }
+      /* Now that we have stripped the elements that need not be in the
+        undo_list any more, we can finally mark the list.  */
+      mark_object (nextb->BUFFER_INTERNAL_FIELD (undo_list));
+    }
 
   gc_sweep ();
 
@@ -5987,9 +5976,10 @@
 #ifdef GC_CHECK_MARKED_OBJECTS
            if (po != &buffer_defaults && po != &buffer_local_symbols)
              {
-               struct buffer *b = all_buffers;
-               for (; b && b != po; b = b->header.next.buffer)
-                 ;
+               struct buffer *b;
+               for_each_buffer (b)
+                 if (b == po)
+                   break;
                if (b == NULL)
                  abort ();
              }

=== modified file 'src/buffer.c'
--- a/src/buffer.c      2012-07-17 11:52:00 +0000
+++ b/src/buffer.c      2012-07-19 03:55:59 +0000
@@ -1532,10 +1532,8 @@
 
       GCPRO1 (buffer);
 
-      for (other = all_buffers; other; other = other->header.next.buffer)
-       /* all_buffers contains dead buffers too;
-          don't re-kill them.  */
-       if (other->base_buffer == b && !NILP (BVAR (other, name)))
+      for_each_buffer (other)
+       if (other->base_buffer == b)
          {
            Lisp_Object buf;
            XSETBUFFER (buf, other);
@@ -2052,7 +2050,7 @@
 
   { /* This is probably harder to make work.  */
     struct buffer *other;
-    for (other = all_buffers; other; other = other->header.next.buffer)
+    for_each_buffer (other)
       if (other->base_buffer == other_buffer
          || other->base_buffer == current_buffer)
        error ("One of the buffers to swap has indirect buffers");
@@ -2429,7 +2427,7 @@
 
   /* Copy this buffer's new multibyte status
      into all of its indirect buffers.  */
-  for (other = all_buffers; other; other = other->header.next.buffer)
+  for_each_buffer (other)
     if (other->base_buffer == current_buffer && !NILP (BVAR (other, name)))
       {
        BVAR (other, enable_multibyte_characters)
@@ -5035,7 +5033,7 @@
       Map new memory.  */
    struct buffer *b;
 
-   for (b = all_buffers; b; b = b->header.next.buffer)
+   for_each_buffer (b)
      if (b->text->beg == NULL)
        enlarge_buffer_text (b, 0);
  }

=== modified file 'src/buffer.h'
--- a/src/buffer.h      2012-07-17 04:29:50 +0000
+++ b/src/buffer.h      2012-07-19 03:55:59 +0000
@@ -857,6 +857,15 @@
 };
 
 
+/* Chain of all buffers, including killed ones.  */
+
+extern struct buffer *all_buffers;
+
+/* Used to iterate over the chain above.  */
+
+#define for_each_buffer(b) \
+  for ((b) = all_buffers; (b); (b) = (b)->header.next.buffer)
+
 /* This points to the current buffer.  */
 
 extern struct buffer *current_buffer;

=== modified file 'src/coding.c'
--- a/src/coding.c      2012-07-11 07:19:44 +0000
+++ b/src/coding.c      2012-07-19 03:55:59 +0000
@@ -7588,7 +7588,7 @@
     {
       if (EQ (workbuf, Vcode_conversion_reused_workbuf))
        reused_workbuf_in_use = 0;
-      else if (! NILP (Fbuffer_live_p (workbuf)))
+      else
        Fkill_buffer (workbuf);
     }
   set_buffer_internal (XBUFFER (current));

=== modified file 'src/data.c'
--- a/src/data.c        2012-07-18 05:44:36 +0000
+++ b/src/data.c        2012-07-19 03:55:59 +0000
@@ -1401,7 +1401,7 @@
              {
                struct buffer *b;
 
-               for (b = all_buffers; b; b = b->header.next.buffer)
+               for_each_buffer (b)
                  if (!PER_BUFFER_VALUE_P (b, idx))
                    PER_BUFFER_VALUE (b, offset) = value;
              }

=== modified file 'src/lisp.h'
--- a/src/lisp.h        2012-07-18 13:20:59 +0000
+++ b/src/lisp.h        2012-07-19 03:55:59 +0000
@@ -2858,7 +2858,6 @@
 extern Lisp_Object other_buffer_safely (Lisp_Object);
 extern Lisp_Object Qpriority, Qwindow, Qbefore_string, Qafter_string;
 extern Lisp_Object get_truename_buffer (Lisp_Object);
-extern struct buffer *all_buffers;
 extern void init_buffer_once (void);
 extern void init_buffer (void);
 extern void syms_of_buffer (void);


reply via email to

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