emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r109510: Inline functions to examine


From: Dmitry Antipov
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r109510: Inline functions to examine and change buffer intervals.
Date: Wed, 08 Aug 2012 16:12:40 +0400
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 109510
committer: Dmitry Antipov <address@hidden>
branch nick: trunk
timestamp: Wed 2012-08-08 16:12:40 +0400
message:
  Inline functions to examine and change buffer intervals.
  * alloc.c (mark_interval_tree): Remove.
  (MARK_INTERVAL_TREE): Simplify.
  (UNMARK_BALANCE_INTERVALS): Remove.  Adjust users.
  * intervals.c (buffer_balance_intervals): New function.
  (graft_intervals_into_buffer): Adjust indentation.
  (set_intervals_multibyte): Simplify.
  * buffer.h (BUF_INTERVALS): Remove.
  (buffer_get_intervals, buffer_set_intervals): New function.
  * alloc.c, buffer.c, editfns.c, fileio.c, indent.c, insdel.c:
  * intervals.c, textprop.c: Adjust users.
modified:
  src/ChangeLog
  src/alloc.c
  src/buffer.c
  src/buffer.h
  src/editfns.c
  src/fileio.c
  src/indent.c
  src/insdel.c
  src/intervals.c
  src/textprop.c
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2012-08-08 10:23:04 +0000
+++ b/src/ChangeLog     2012-08-08 12:12:40 +0000
@@ -1,5 +1,19 @@
 2012-08-08  Dmitry Antipov  <address@hidden>
 
+       Inline functions to examine and change buffer intervals.
+       * alloc.c (mark_interval_tree): Remove.
+       (MARK_INTERVAL_TREE): Simplify.
+       (UNMARK_BALANCE_INTERVALS): Remove.  Adjust users.
+       * intervals.c (buffer_balance_intervals): New function.
+       (graft_intervals_into_buffer): Adjust indentation.
+       (set_intervals_multibyte): Simplify.
+       * buffer.h (BUF_INTERVALS): Remove.
+       (buffer_get_intervals, buffer_set_intervals): New function.
+       * alloc.c, buffer.c, editfns.c, fileio.c, indent.c, insdel.c:
+       * intervals.c, textprop.c: Adjust users.
+
+2012-08-08  Dmitry Antipov  <address@hidden>
+
        Inline functions to examine and change string intervals.
        * lisp.h (STRING_INTERVALS, STRING_SET_INTERVALS): Remove.
        (string_get_intervals, string_set_intervals): New function.

=== modified file 'src/alloc.c'
--- a/src/alloc.c       2012-08-08 10:23:04 +0000
+++ b/src/alloc.c       2012-08-08 12:12:40 +0000
@@ -1542,35 +1542,12 @@
   mark_object (i->plist);
 }
 
-
-/* Mark the interval tree rooted in TREE.  Don't call this directly;
-   use the macro MARK_INTERVAL_TREE instead.  */
-
-static void
-mark_interval_tree (register INTERVAL tree)
-{
-  /* No need to test if this tree has been marked already; this
-     function is always called through the MARK_INTERVAL_TREE macro,
-     which takes care of that.  */
-
-  traverse_intervals_noorder (tree, mark_interval, Qnil);
-}
-
-
 /* Mark the interval tree rooted in I.  */
 
-#define MARK_INTERVAL_TREE(i)  \
-  do {                         \
-    if (i && !i->gcmarkbit)    \
-      mark_interval_tree (i);  \
-  } while (0)
-
-/* Unmark and rebalance interval tree rooted in I.  */
-
-#define UNMARK_BALANCE_INTERVALS(i)    \
-  do {                                 \
-   if (i)                              \
-     (i) = balance_intervals (i);      \
+#define MARK_INTERVAL_TREE(i)                                  \
+  do {                                                         \
+    if (i && !i->gcmarkbit)                                    \
+      traverse_intervals_noorder (i, mark_interval, Qnil);     \
   } while (0)
 
 /***********************************************************************
@@ -2101,8 +2078,8 @@
                  /* String is live; unmark it and its intervals.  */
                  UNMARK_STRING (s);
 
-                 if (s->intervals)
-                   UNMARK_BALANCE_INTERVALS (s->intervals);
+                 /* Do not use string_(set|get)_intervals here.  */
+                 s->intervals = balance_intervals (s->intervals);
 
                  ++total_strings;
                  total_string_bytes += STRING_BYTES (s);
@@ -5848,7 +5825,7 @@
 
   /* ...but there are some buffer-specific things.  */
 
-  MARK_INTERVAL_TREE (BUF_INTERVALS (buffer));
+  MARK_INTERVAL_TREE (buffer_get_intervals (buffer));
 
   /* For now, we just don't mark the undo_list.  It's done later in
      a special way just before the sweep phase, and after stripping
@@ -6587,7 +6564,8 @@
       else
        {
          VECTOR_UNMARK (buffer);
-         UNMARK_BALANCE_INTERVALS (BUF_INTERVALS (buffer));
+         /* Do not use buffer_(set|get)_intervals here.  */
+         buffer->text->intervals = balance_intervals (buffer->text->intervals);
          total_buffers++;
          prev = buffer, buffer = buffer->header.next.buffer;
        }

=== modified file 'src/buffer.c'
--- a/src/buffer.c      2012-08-08 10:23:04 +0000
+++ b/src/buffer.c      2012-08-08 12:12:40 +0000
@@ -360,7 +360,7 @@
   BUF_CHARS_MODIFF (b) = 1;
   BUF_OVERLAY_MODIFF (b) = 1;
   BUF_SAVE_MODIFF (b) = 1;
-  BUF_INTERVALS (b) = NULL;
+  buffer_set_intervals (b, NULL);
   BUF_UNCHANGED_MODIFIED (b) = 1;
   BUF_OVERLAY_UNCHANGED_MODIFIED (b) = 1;
   BUF_END_UNCHANGED (b) = 0;
@@ -1688,7 +1688,7 @@
          m = next;
        }
       BUF_MARKERS (b) = NULL;
-      BUF_INTERVALS (b) = NULL;
+      buffer_set_intervals (b, NULL);
 
       /* Perhaps we should explicitly free the interval tree here... */
     }
@@ -4904,8 +4904,8 @@
   /* No one will share the text with these buffers, but let's play it safe.  */
   buffer_defaults.indirections = 0;
   buffer_local_symbols.indirections = 0;
-  BUF_INTERVALS (&buffer_defaults) = NULL;
-  BUF_INTERVALS (&buffer_local_symbols) = NULL;
+  buffer_set_intervals (&buffer_defaults, NULL);
+  buffer_set_intervals (&buffer_local_symbols, NULL);
   XSETPVECTYPESIZE (&buffer_defaults, PVEC_BUFFER, pvecsize);
   XSETBUFFER (Vbuffer_defaults, &buffer_defaults);
   XSETPVECTYPESIZE (&buffer_local_symbols, PVEC_BUFFER, pvecsize);

=== modified file 'src/buffer.h'
--- a/src/buffer.h      2012-08-07 13:37:21 +0000
+++ b/src/buffer.h      2012-08-08 12:12:40 +0000
@@ -193,9 +193,6 @@
 /* FIXME: should we move this into ->text->auto_save_modiff?  */
 #define BUF_AUTOSAVE_MODIFF(buf) ((buf)->auto_save_modified)
 
-/* Interval tree of buffer.  */
-#define BUF_INTERVALS(buf) ((buf)->text->intervals)
-
 /* Marker chain of buffer.  */
 #define BUF_MARKERS(buf) ((buf)->text->markers)
 
@@ -951,7 +948,25 @@
 extern Lisp_Object Qbefore_change_functions;
 extern Lisp_Object Qafter_change_functions;
 extern Lisp_Object Qfirst_change_hook;
-
+
+/* Get text properties of B.  */
+
+BUFFER_INLINE INTERVAL
+buffer_get_intervals (struct buffer *b)
+{
+  eassert (b->text != NULL);
+  return b->text->intervals;
+}
+
+/* Set text properties of B to I.  */
+
+BUFFER_INLINE void
+buffer_set_intervals (struct buffer *b, INTERVAL i)
+{
+  eassert (b->text != NULL);
+  b->text->intervals = i;
+}
+
 /* Return character code of multi-byte form at byte position POS.  If POS
    doesn't point the head of valid multi-byte form, only the byte at
    POS is returned.  No range checking.

=== modified file 'src/editfns.c'
--- a/src/editfns.c     2012-08-08 10:23:04 +0000
+++ b/src/editfns.c     2012-08-08 12:12:40 +0000
@@ -4527,7 +4527,7 @@
   Lisp_Object buf;
 
   XSETBUFFER (buf, current_buffer);
-  cur_intv = BUF_INTERVALS (current_buffer);
+  cur_intv = buffer_get_intervals (current_buffer);
 
   validate_region (&startr1, &endr1);
   validate_region (&startr2, &endr2);

=== modified file 'src/fileio.c'
--- a/src/fileio.c      2012-08-08 06:11:29 +0000
+++ b/src/fileio.c      2012-08-08 12:12:40 +0000
@@ -3145,7 +3145,7 @@
     set_buffer_internal (XBUFFER (buffer));
   adjust_markers_for_delete (BEG, BEG_BYTE, Z, Z_BYTE);
   adjust_overlays_for_delete (BEG, Z - BEG);
-  BUF_INTERVALS (current_buffer) = NULL;
+  buffer_set_intervals (current_buffer, NULL);
   TEMP_SET_PT_BOTH (BEG, BEG_BYTE);
 
   /* Now we are safe to change the buffer's multibyteness directly.  */

=== modified file 'src/indent.c'
--- a/src/indent.c      2012-08-07 07:33:18 +0000
+++ b/src/indent.c      2012-08-08 12:12:40 +0000
@@ -336,7 +336,7 @@
 
   /* If the buffer has overlays, text properties,
      or multibyte characters, use a more general algorithm.  */
-  if (BUF_INTERVALS (current_buffer)
+  if (buffer_get_intervals (current_buffer)
       || current_buffer->overlays_before
       || current_buffer->overlays_after
       || Z != Z_BYTE)

=== modified file 'src/insdel.c'
--- a/src/insdel.c      2012-08-08 10:23:04 +0000
+++ b/src/insdel.c      2012-08-08 12:12:40 +0000
@@ -844,10 +844,10 @@
                             PT + nchars, PT_BYTE + nbytes,
                             before_markers);
 
-  if (BUF_INTERVALS (current_buffer))
+  if (buffer_get_intervals (current_buffer))
     offset_intervals (current_buffer, PT, nchars);
 
-  if (!inherit && BUF_INTERVALS (current_buffer))
+  if (!inherit && buffer_get_intervals (current_buffer))
     set_text_properties (make_number (PT), make_number (PT + nchars),
                         Qnil, Qnil, Qnil);
 
@@ -1017,7 +1017,7 @@
   adjust_markers_for_insert (GPT - nchars, GPT_BYTE - nbytes,
                             GPT, GPT_BYTE, 0);
 
-  if (BUF_INTERVALS (current_buffer))
+  if (buffer_get_intervals (current_buffer))
     {
       offset_intervals (current_buffer, GPT - nchars, nchars);
       graft_intervals_into_buffer (NULL, GPT - nchars, nchars,
@@ -1157,11 +1157,11 @@
                             PT_BYTE + outgoing_nbytes,
                             0);
 
-  if (BUF_INTERVALS (current_buffer))
+  if (buffer_get_intervals (current_buffer))
     offset_intervals (current_buffer, PT, nchars);
 
   /* Get the intervals for the part of the string we are inserting.  */
-  intervals = BUF_INTERVALS (buf);
+  intervals = buffer_get_intervals (buf);
   if (nchars < BUF_Z (buf) - BUF_BEG (buf))
     {
       if (buf == current_buffer && PT <= from)
@@ -1225,10 +1225,9 @@
     adjust_overlays_for_insert (from, len - nchars_del);
   else if (len < nchars_del)
     adjust_overlays_for_delete (from, nchars_del - len);
-  if (BUF_INTERVALS (current_buffer))
-    {
-      offset_intervals (current_buffer, from, len - nchars_del);
-    }
+
+  if (buffer_get_intervals (current_buffer))
+    offset_intervals (current_buffer, from, len - nchars_del);
 
   if (from < PT)
     adjust_point (len - nchars_del, len_byte - nbytes_del);
@@ -1823,7 +1822,7 @@
   if (XBUFFER (XWINDOW (selected_window)->buffer) != current_buffer)
     ++windows_or_buffers_changed;
 
-  if (BUF_INTERVALS (current_buffer))
+  if (buffer_get_intervals (current_buffer))
     {
       if (preserve_ptr)
        {

=== modified file 'src/intervals.c'
--- a/src/intervals.c   2012-08-08 10:23:04 +0000
+++ b/src/intervals.c   2012-08-08 12:12:40 +0000
@@ -77,7 +77,7 @@
       new->total_length = (BUF_Z (XBUFFER (parent))
                           - BUF_BEG (XBUFFER (parent)));
       eassert (0 <= TOTAL_LENGTH (new));
-      BUF_INTERVALS (XBUFFER (parent)) = new;
+      buffer_set_intervals (XBUFFER (parent), new);
       new->position = BEG;
     }
   else if (STRINGP (parent))
@@ -453,7 +453,7 @@
   if (have_parent)
     {
       if (BUFFERP (parent))
-       BUF_INTERVALS (XBUFFER (parent)) = interval;
+       buffer_set_intervals (XBUFFER (parent), interval);
       else if (STRINGP (parent))
        string_set_intervals (parent, interval);
     }
@@ -483,6 +483,19 @@
   return tree ? balance_intervals_internal (tree) : NULL;
 }
 
+/* Rebalance text properties of B.  */
+
+static void
+buffer_balance_intervals (struct buffer *b)
+{
+  INTERVAL i;
+
+  eassert (b != NULL);
+  i = buffer_get_intervals (b);
+  if (i)
+    buffer_set_intervals (b, balance_an_interval (i));
+}
+
 /* Split INTERVAL into two pieces, starting the second piece at
    character position OFFSET (counting from 0), relative to INTERVAL.
    INTERVAL becomes the left-hand piece, and the right-hand piece
@@ -1204,7 +1217,7 @@
        interval_set_object (parent, owner);
 
       if (BUFFERP (owner))
-       BUF_INTERVALS (XBUFFER (owner)) = parent;
+       buffer_set_intervals (XBUFFER (owner), parent);
       else if (STRINGP (owner))
        string_set_intervals (owner, parent);
       else
@@ -1306,7 +1319,7 @@
                               ptrdiff_t start, ptrdiff_t length)
 {
   register ptrdiff_t left_to_delete = length;
-  register INTERVAL tree = BUF_INTERVALS (buffer);
+  register INTERVAL tree = buffer_get_intervals (buffer);
   Lisp_Object parent;
   ptrdiff_t offset;
 
@@ -1321,7 +1334,7 @@
 
   if (length == TOTAL_LENGTH (tree))
     {
-      BUF_INTERVALS (buffer) = NULL;
+      buffer_set_intervals (buffer, NULL);
       return;
     }
 
@@ -1338,10 +1351,10 @@
     {
       left_to_delete -= interval_deletion_adjustment (tree, start - offset,
                                                      left_to_delete);
-      tree = BUF_INTERVALS (buffer);
+      tree = buffer_get_intervals (buffer);
       if (left_to_delete == tree->total_length)
        {
-         BUF_INTERVALS (buffer) = NULL;
+         buffer_set_intervals (buffer, NULL);
          return;
        }
     }
@@ -1359,11 +1372,12 @@
 void
 offset_intervals (struct buffer *buffer, ptrdiff_t start, ptrdiff_t length)
 {
-  if (!BUF_INTERVALS (buffer) || length == 0)
+  if (!buffer_get_intervals (buffer) || length == 0)
     return;
 
   if (length > 0)
-    adjust_intervals_for_insertion (BUF_INTERVALS (buffer), start, length);
+    adjust_intervals_for_insertion (buffer_get_intervals (buffer),
+                                   start, length);
   else
     {
       IF_LINT (if (length < - TYPE_MAXIMUM (ptrdiff_t)) abort ();)
@@ -1570,7 +1584,7 @@
   register INTERVAL tree;
   ptrdiff_t over_used;
 
-  tree = BUF_INTERVALS (buffer);
+  tree = buffer_get_intervals (buffer);
 
   /* If the new text has no properties, then with inheritance it
      becomes part of whatever interval it was inserted into.
@@ -1586,31 +1600,34 @@
                                 make_number (position + length),
                                 Qnil, buf, 0);
        }
-      if (BUF_INTERVALS (buffer))
-       /* Shouldn't be necessary.  --Stef  */
-       BUF_INTERVALS (buffer) = balance_an_interval (BUF_INTERVALS (buffer));
+      /* Shouldn't be necessary.  --Stef  */
+      buffer_balance_intervals (buffer);
       return;
     }
 
   eassert (length == TOTAL_LENGTH (source));
 
   if ((BUF_Z (buffer) - BUF_BEG (buffer)) == length)
-    {  /* The inserted text constitutes the whole buffer, so
+    { 
+      /* The inserted text constitutes the whole buffer, so
         simply copy over the interval structure.  */
-         Lisp_Object buf;
-         XSETBUFFER (buf, buffer);
-         BUF_INTERVALS (buffer) = reproduce_tree_obj (source, buf);
-      BUF_INTERVALS (buffer)->position = BUF_BEG (buffer);
-      eassert (BUF_INTERVALS (buffer)->up_obj == 1);
-         return;
-       }
+      Lisp_Object buf;
+
+      XSETBUFFER (buf, buffer);
+      buffer_set_intervals (buffer, reproduce_tree_obj (source, buf));
+      buffer_get_intervals (buffer)->position = BUF_BEG (buffer);
+      eassert (buffer_get_intervals (buffer)->up_obj == 1);
+      return;
+    }
   else if (!tree)
-    { /* Create an interval tree in which to place a copy
+    {
+      /* Create an interval tree in which to place a copy
         of the intervals of the inserted string.  */
        Lisp_Object buf;
+
        XSETBUFFER (buf, buffer);
        tree = create_root_interval (buf);
-      }
+    }
   /* Paranoia -- the text has already been added, so
      this buffer should be of non-zero length.  */
   eassert (TOTAL_LENGTH (tree) > 0);
@@ -1691,9 +1708,7 @@
       under = next_interval (this);
     }
 
-  if (BUF_INTERVALS (buffer))
-    BUF_INTERVALS (buffer) = balance_an_interval (BUF_INTERVALS (buffer));
-  return;
+  buffer_balance_intervals (buffer);
 }
 
 /* Get the value of property PROP from PLIST,
@@ -1860,7 +1875,7 @@
 
   /* If we have no text properties and overlays,
      then we can do it quickly.  */
-  if (!BUF_INTERVALS (current_buffer) && ! have_overlays)
+  if (!buffer_get_intervals (current_buffer) && ! have_overlays)
     {
       temp_set_point_both (current_buffer, charpos, bytepos);
       return;
@@ -1869,7 +1884,7 @@
   /* Set TO to the interval containing the char after CHARPOS,
      and TOPREV to the interval containing the char before CHARPOS.
      Either one may be null.  They may be equal.  */
-  to = find_interval (BUF_INTERVALS (current_buffer), charpos);
+  to = find_interval (buffer_get_intervals (current_buffer), charpos);
   if (charpos == BEGV)
     toprev = 0;
   else if (to && to->position == charpos)
@@ -1883,7 +1898,7 @@
      and FROMPREV to the interval containing the char before PT.
      Either one may be null.  They may be equal.  */
   /* We could cache this and save time.  */
-  from = find_interval (BUF_INTERVALS (current_buffer), buffer_point);
+  from = find_interval (buffer_get_intervals (current_buffer), buffer_point);
   if (buffer_point == BEGV)
     fromprev = 0;
   else if (from && from->position == PT)
@@ -1989,7 +2004,7 @@
       /* Set TO to the interval containing the char after CHARPOS,
         and TOPREV to the interval containing the char before CHARPOS.
         Either one may be null.  They may be equal.  */
-      to = find_interval (BUF_INTERVALS (current_buffer), charpos);
+      to = find_interval (buffer_get_intervals (current_buffer), charpos);
       if (charpos == BEGV)
        toprev = 0;
       else if (to && to->position == charpos)
@@ -2122,9 +2137,9 @@
   INTERVAL i, prev, next;
 
   if (NILP (object))
-    i = find_interval (BUF_INTERVALS (current_buffer), pos);
+    i = find_interval (buffer_get_intervals (current_buffer), pos);
   else if (BUFFERP (object))
-    i = find_interval (BUF_INTERVALS (XBUFFER (object)), pos);
+    i = find_interval (buffer_get_intervals (XBUFFER (object)), pos);
   else if (STRINGP (object))
     i = find_interval (string_get_intervals (object), pos);
   else
@@ -2253,7 +2268,7 @@
 copy_intervals_to_string (Lisp_Object string, struct buffer *buffer,
                          ptrdiff_t position, ptrdiff_t length)
 {
-  INTERVAL interval_copy = copy_intervals (BUF_INTERVALS (buffer),
+  INTERVAL interval_copy = copy_intervals (buffer_get_intervals (buffer),
                                           position, length);
   if (!interval_copy)
     return;
@@ -2418,7 +2433,8 @@
 void
 set_intervals_multibyte (int multi_flag)
 {
-  if (BUF_INTERVALS (current_buffer))
-    set_intervals_multibyte_1 (BUF_INTERVALS (current_buffer), multi_flag,
-                              BEG, BEG_BYTE, Z, Z_BYTE);
+  INTERVAL i = buffer_get_intervals (current_buffer);
+
+  if (i)
+    set_intervals_multibyte_1 (i, multi_flag, BEG, BEG_BYTE, Z, Z_BYTE);
 }

=== modified file 'src/textprop.c'
--- a/src/textprop.c    2012-08-08 10:23:04 +0000
+++ b/src/textprop.c    2012-08-08 12:12:40 +0000
@@ -143,7 +143,7 @@
       if (!(BUF_BEGV (b) <= XINT (*begin) && XINT (*begin) <= XINT (*end)
            && XINT (*end) <= BUF_ZV (b)))
        args_out_of_range (*begin, *end);
-      i = BUF_INTERVALS (b);
+      i = buffer_get_intervals (b);
 
       /* If there's no text, there are no properties.  */
       if (BUF_BEGV (b) == BUF_ZV (b))
@@ -510,7 +510,7 @@
 
       beg = BUF_BEGV (b);
       end = BUF_ZV (b);
-      i = BUF_INTERVALS (b);
+      i = buffer_get_intervals (b);
     }
   else
     {
@@ -1338,8 +1338,8 @@
   else
     return;
 
-  if (i == 0)
-    i = find_interval (BUF_INTERVALS (XBUFFER (buffer)), s);
+  if (i == NULL)
+    i = find_interval (buffer_get_intervals (XBUFFER (buffer)), s);
 
   if (i->position != s)
     {
@@ -1993,7 +1993,7 @@
 verify_interval_modification (struct buffer *buf,
                              ptrdiff_t start, ptrdiff_t end)
 {
-  register INTERVAL intervals = BUF_INTERVALS (buf);
+  register INTERVAL intervals = buffer_get_intervals (buf);
   register INTERVAL i;
   Lisp_Object hooks;
   register Lisp_Object prev_mod_hooks;


reply via email to

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