changeset 5879:77d7b77909c2

Move extents.c to working in byte positions only; fix a bug, extent_detach() src/ChangeLog addition: 2015-03-27 Aidan Kehoe <kehoea@parhasard.net> Fix a small bug, extent_detach(); minimise needless char-byte conversion, extents.c, sticking to byte positions in general in this file. * extents.c: * extents.c (signal_single_extent_changed): Pass byte endpoints to gutter_extent_signal_changed_region_maybe(), buffer_extent_signal_changed_region(). * extents.c (extent_detach): Call signal_extent_changed() correctly, pass both extent endpoints rather than just the byte and character variants of the start. * extents.c (struct report_extent_modification_closure): Do this in terms of byte positions. * extents.c (report_extent_modification_mapper): Use byte positions, only converting to characters when we are definitely calling Lisp. * extents.c (report_extent_modification): Use byte positions in this API, move the byte-char conversion to our callers, simplifying extents.c (it all now works in byte positions). * extents.h: Update report_extent_modification's prototype. * gutter.c (gutter_extent_signal_changed_region_maybe): Use byte positions here, avoids needless byte-char conversion. * gutter.h: Update the prototype here. * insdel.c: * insdel.c (buffer_extent_signal_changed_region): Implement this in terms of byte positions. * insdel.c (signal_before_change): * insdel.c (signal_after_change): Call report_extent_modification() with byte positions, doing the char->byte conversion here rather than leaving it to extents.c. * insdel.h: * insdel.h (struct each_buffer_change_data): The extent unchanged info now describes bytecounts.
author Aidan Kehoe <kehoea@parhasard.net>
date Fri, 27 Mar 2015 23:39:49 +0000
parents 916187a03b82
children 44ba043ceada
files src/ChangeLog src/extents.c src/extents.h src/gutter.c src/gutter.h src/insdel.c src/insdel.h
diffstat 7 files changed, 89 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Thu Mar 26 20:47:12 2015 -0400
+++ b/src/ChangeLog	Fri Mar 27 23:39:49 2015 +0000
@@ -1,3 +1,42 @@
+2015-03-27  Aidan Kehoe  <kehoea@parhasard.net>
+
+	Fix a small bug, extent_detach(); minimise needless char-byte
+	conversion, extents.c, sticking to byte positions in general in
+	this file.
+	* extents.c:
+	* extents.c (signal_single_extent_changed):
+	Pass byte endpoints to
+	gutter_extent_signal_changed_region_maybe(),
+	buffer_extent_signal_changed_region().
+	* extents.c (extent_detach):
+	Call signal_extent_changed() correctly, pass both extent endpoints
+	rather than just the byte and character variants of the start.
+	* extents.c (struct report_extent_modification_closure):
+	Do this in terms of byte positions.
+	* extents.c (report_extent_modification_mapper):
+	Use byte positions, only converting to characters when we are
+	definitely calling Lisp.
+	* extents.c (report_extent_modification):
+	Use byte positions in this API, move the byte-char conversion to
+	our callers, simplifying extents.c (it all now works in byte
+	positions). 
+	* extents.h:
+	Update report_extent_modification's prototype.
+	* gutter.c (gutter_extent_signal_changed_region_maybe):
+	Use byte positions here, avoids needless byte-char conversion.
+	* gutter.h:
+	Update the prototype here.
+	* insdel.c:
+	* insdel.c (buffer_extent_signal_changed_region):
+	Implement this in terms of byte positions.
+	* insdel.c (signal_before_change):
+	* insdel.c (signal_after_change):
+	Call report_extent_modification() with byte positions, doing the
+	char->byte conversion here rather than leaving it to extents.c.
+	* insdel.h:
+	* insdel.h (struct each_buffer_change_data):
+	The extent unchanged info now describes bytecounts. 
+
 2015-03-26  Vin Shelton  <acs@xemacs.org>
 
         * m/x86_64.h: Deleted; caused bogus GNUMakefile generation
--- a/src/extents.c	Thu Mar 26 20:47:12 2015 -0400
+++ b/src/extents.c	Fri Mar 27 23:39:49 2015 +0000
@@ -1473,8 +1473,8 @@
 	  if (!in_modeline_generation)
 	    MARK_EXTENTS_CHANGED;
 	  gutter_extent_signal_changed_region_maybe
-	    (object, extent_endpoint_char (extent, 0),
-	     extent_endpoint_char (extent, 1));
+            (object, extent_endpoint_byte (extent, 0),
+	     extent_endpoint_byte (extent, 1));
 	}
       else if (BUFFERP (object))
 	{
@@ -1486,8 +1486,8 @@
 	      EQ (property, Qinvisible))
 	    MARK_CLIP_CHANGED;
 	  buffer_extent_signal_changed_region
-	    (b, extent_endpoint_char (extent, 0),
-	     extent_endpoint_char (extent, 1));
+            (b, extent_endpoint_byte (extent, 0),
+	     extent_endpoint_byte (extent, 1));
 	}
     }
 
@@ -1696,10 +1696,8 @@
   el = extent_extent_list (extent);
 
   /* call this before messing with the extent. */
-  signal_extent_changed (extent, Qnil,
-			 extent_endpoint_byte (extent, 0),
-			 extent_endpoint_char (extent, 0),
-			 0);
+  signal_extent_changed (extent, Qnil, extent_endpoint_byte (extent, 0),
+			 extent_endpoint_byte (extent, 1), 0);
   extent_list_delete (el, extent);
   soe_delete (extent_object (extent), extent);
   set_extent_start (extent, -1);
@@ -4632,7 +4630,7 @@
 struct report_extent_modification_closure
 {
   Lisp_Object buffer;
-  Charxpos start, end;
+  Bytexpos start, end;
   int afterp;
   int speccount;
 };
@@ -4658,8 +4656,12 @@
     return 0;
 
   exobj = wrap_extent (extent);
-  startobj = make_fixnum (closure->start);
-  endobj = make_fixnum (closure->end);
+  startobj
+    = make_fixnum (buffer_or_string_bytexpos_to_charxpos
+                   (extent_object (extent), closure->start));
+  endobj
+    = make_fixnum (buffer_or_string_bytexpos_to_charxpos
+                   (extent_object (extent), closure->end));
 
   /* Now that we are sure to call elisp, set up an unwind-protect so
      inside_change_hook gets restored in case we throw.  Also record
@@ -4704,7 +4706,7 @@
 }
 
 void
-report_extent_modification (Lisp_Object buffer, Charbpos start, Charbpos end,
+report_extent_modification (Lisp_Object buffer, Bytexpos start, Bytexpos end,
 			    int afterp)
 {
   struct report_extent_modification_closure closure;
@@ -4715,10 +4717,8 @@
   closure.afterp = afterp;
   closure.speccount = -1;
 
-  map_extents (charbpos_to_bytebpos (XBUFFER (buffer), start),
-	       charbpos_to_bytebpos (XBUFFER (buffer), end),
-	       report_extent_modification_mapper, (void *)&closure,
-	       buffer, NULL, ME_MIGHT_CALL_ELISP);
+  map_extents (start, end, report_extent_modification_mapper,
+               (void *)&closure, buffer, NULL, ME_MIGHT_CALL_ELISP);
 }
 
 
--- a/src/extents.h	Thu Mar 26 20:47:12 2015 -0400
+++ b/src/extents.h	Fri Mar 27 23:39:49 2015 +0000
@@ -181,9 +181,8 @@
 				    Bytexpos opoint, Bytecount length);
 void process_extents_for_deletion (Lisp_Object object, Bytexpos from,
 				   Bytexpos to, int destroy_them);
-/* Note the following function is in Charbpos's */
-void report_extent_modification (Lisp_Object buffer, Charbpos start,
-				 Charbpos end, int afterp);
+void report_extent_modification (Lisp_Object buffer, Bytexpos start,
+				 Bytexpos end, int afterp);
 void add_string_extents (Lisp_Object string, struct buffer *buf,
 			 Bytexpos opoint, Bytecount length);
 void splice_in_string_extents (Lisp_Object string, struct buffer *buf,
--- a/src/gutter.c	Thu Mar 26 20:47:12 2015 -0400
+++ b/src/gutter.c	Fri Mar 27 23:39:49 2015 +0000
@@ -522,8 +522,8 @@
    knows exactly what extents have changed. */
 void
 gutter_extent_signal_changed_region_maybe (Lisp_Object obj,
-					   Charbpos UNUSED (start),
-					   Charbpos UNUSED (end))
+					   Bytexpos UNUSED (start),
+					   Bytexpos UNUSED (end))
 {
   /* #### Start and end are currently ignored but could be used by a
      more optimal gutter redisplay. We currently loop over all frames
--- a/src/gutter.h	Thu Mar 26 20:47:12 2015 -0400
+++ b/src/gutter.h	Fri Mar 27 23:39:49 2015 +0000
@@ -50,7 +50,7 @@
 			     int height);
 void reset_gutter_display_lines (struct frame* f);
 void gutter_extent_signal_changed_region_maybe (Lisp_Object obj,
-						Charbpos start, Charbpos end);
+						Bytexpos start, Bytexpos end);
 int display_boxes_in_gutter_p (struct frame *f, struct display_box* db,
 			       struct display_glyph_area* dga);
 
--- a/src/insdel.c	Thu Mar 26 20:47:12 2015 -0400
+++ b/src/insdel.c	Fri Mar 27 23:39:49 2015 +0000
@@ -570,15 +570,15 @@
 }
 
 void
-buffer_extent_signal_changed_region (struct buffer *buf, Charbpos start,
-				     Charbpos end)
+buffer_extent_signal_changed_region (struct buffer *buf, Bytebpos start,
+				     Bytebpos end)
 {
   if (buf->changes->begin_extent_unchanged < 0 ||
-      buf->changes->begin_extent_unchanged > start - BUF_BEG (buf))
-    buf->changes->begin_extent_unchanged = start - BUF_BEG (buf);
+      buf->changes->begin_extent_unchanged > start - BYTE_BUF_BEG (buf))
+    buf->changes->begin_extent_unchanged = start - BYTE_BUF_BEG (buf);
   if (buf->changes->end_extent_unchanged < 0 ||
-      buf->changes->end_extent_unchanged > BUF_Z (buf) - end)
-    buf->changes->end_extent_unchanged = BUF_Z (buf) - end;
+      buf->changes->end_extent_unchanged > BYTE_BUF_Z (buf) - end)
+    buf->changes->end_extent_unchanged = BYTE_BUF_Z (buf) - end;
 }
 
 void
@@ -837,10 +837,16 @@
       if (end < BUF_BEGV (buf)) end = BUF_BEGV (buf);
       if (end > BUF_ZV (buf))   end = BUF_ZV (buf);
 
-      MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
-	{
-	  report_extent_modification (wrap_buffer (mbuf), start, end, 0);
-	}
+      {
+        Bytexpos byte_start = charbpos_to_bytebpos (buf, start);
+        Bytexpos byte_end = charbpos_to_bytebpos (buf, end);
+
+        MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
+          {
+            report_extent_modification (wrap_buffer (mbuf), byte_start,
+                                        byte_end, 0);
+          }
+      }
       unbind_to (speccount);
 
       /* Only now do we indicate that the before-change-functions have
@@ -930,12 +936,17 @@
       if (orig_end < BUF_BEGV (buf)) orig_end = BUF_BEGV (buf);
       if (orig_end > BUF_ZV (buf))   orig_end = BUF_ZV (buf);
 
-      MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
-	{
-	  buffer = wrap_buffer (mbuf);
-	  report_extent_modification (buffer, start, new_end, 1);
-	}
-      unbind_to (speccount); /* sets inside_change_hook back to 0 */
+      {
+        Bytexpos byte_start = charbpos_to_bytebpos (buf, start);
+        Bytexpos byte_new_end = charbpos_to_bytebpos (buf, new_end);
+
+        MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
+          {
+            buffer = wrap_buffer (mbuf);
+            report_extent_modification (buffer, byte_start, byte_new_end, 1);
+          }
+        unbind_to (speccount); /* sets inside_change_hook back to 0 */
+      }
     }
 }
 
--- a/src/insdel.h	Thu Mar 26 20:47:12 2015 -0400
+++ b/src/insdel.h	Fri Mar 27 23:39:49 2015 +0000
@@ -99,7 +99,7 @@
   /* redisplay needs to know if a newline was deleted so its
      incremental-redisplay algorithm will fail */
   int newline_was_deleted;
-  Charcount begin_extent_unchanged, end_extent_unchanged;
+  Bytecount begin_extent_unchanged, end_extent_unchanged;
 };
 
 /* Number of characters at the beginning and end of the buffer that
@@ -111,7 +111,7 @@
 #define BUF_BEGIN_UNCHANGED(buf) ((buf)->changes->begin_unchanged)
 #define BUF_END_UNCHANGED(buf) ((buf)->changes->end_unchanged)
 
-/* Number of characters at the beginning and end of the buffer that
+/* Number of bytes at the beginning and end of the buffer that
    have not had a covering extent change since the last call to
    buffer_reset_changes ().  If no changes have occurred since then,
    both values will be -1.