Invalidate region caches only if buffer text is going to be changed.
[bpt/emacs.git] / src / textprop.c
index 282ae11..b804f34 100644 (file)
@@ -93,15 +93,25 @@ text_read_only (Lisp_Object propval)
   xsignal0 (Qtext_read_only);
 }
 
-/* Prepare to modify the region of BUFFER from START to END.  */
+/* Prepare to modify the text properties of BUFFER from START to END.  */
 
 static void
-modify_region (Lisp_Object buffer, Lisp_Object start, Lisp_Object end)
+modify_text_properties (Lisp_Object buffer, Lisp_Object start, Lisp_Object end)
 {
+  ptrdiff_t b = XINT (start), e = XINT (end);
   struct buffer *buf = XBUFFER (buffer), *old = current_buffer;
 
   set_buffer_internal (buf);
-  modify_region_1 (XINT (start), XINT (end), true);
+
+  prepare_to_modify_buffer_1 (b, e, NULL);
+
+  BUF_COMPUTE_UNCHANGED (buf, b - 1, e);
+  if (MODIFF <= SAVE_MODIFF)
+    record_first_change ();
+  MODIFF++;
+
+  bset_point_before_scroll (current_buffer, Qnil);
+
   set_buffer_internal (old);
 }
 
@@ -1213,9 +1223,9 @@ add_text_properties_1 (Lisp_Object start, Lisp_Object end,
       ptrdiff_t prev_total_length = TOTAL_LENGTH (i);
       ptrdiff_t prev_pos = i->position;
 
-      modify_region (object, start, end);
+      modify_text_properties (object, start, end);
       /* If someone called us recursively as a side effect of
-        modify_region, and changed the intervals behind our back
+        modify_text_properties, and changed the intervals behind our back
         (could happen if lock_file, called by prepare_to_modify_buffer,
         triggers redisplay, and that calls add-text-properties again
         in the same buffer), we cannot continue with I, because its
@@ -1357,7 +1367,8 @@ into it.  */)
    otherwise.  */
 
 Lisp_Object
-set_text_properties (Lisp_Object start, Lisp_Object end, Lisp_Object properties, Lisp_Object object, Lisp_Object coherent_change_p)
+set_text_properties (Lisp_Object start, Lisp_Object end, Lisp_Object properties,
+                    Lisp_Object object, Lisp_Object coherent_change_p)
 {
   register INTERVAL i;
   Lisp_Object ostart, oend;
@@ -1403,7 +1414,7 @@ set_text_properties (Lisp_Object start, Lisp_Object end, Lisp_Object properties,
     }
 
   if (BUFFERP (object) && !NILP (coherent_change_p))
-    modify_region (object, start, end);
+    modify_text_properties (object, start, end);
 
   set_text_properties_1 (start, end, properties, object, i);
 
@@ -1558,9 +1569,9 @@ Use `set-text-properties' if you want to remove all text properties.  */)
       ptrdiff_t prev_total_length = TOTAL_LENGTH (i);
       ptrdiff_t prev_pos = i->position;
 
-      modify_region (object, start, end);
+      modify_text_properties (object, start, end);
       /* If someone called us recursively as a side effect of
-        modify_region, and changed the intervals behind our back
+        modify_text_properties, and changed the intervals behind our back
         (could happen if lock_file, called by prepare_to_modify_buffer,
         triggers redisplay, and that calls add-text-properties again
         in the same buffer), we cannot continue with I, because its
@@ -1667,9 +1678,9 @@ Return t if any property was actually removed, nil otherwise.  */)
 
   /* We are at the beginning of an interval, with len to scan.
      The flag `modified' records if changes have been made.
-     When object is a buffer, we must call modify_region before changes are
-     made and signal_after_change when we are done.
-     We call modify_region before calling remove_properties if modified == 0,
+     When object is a buffer, we must call modify_text_properties
+     before changes are made and signal_after_change when we are done.
+     We call modify_text_properties before calling remove_properties if modified == 0,
      and we call signal_after_change before returning if modified != 0. */
   for (;;)
     {
@@ -1693,7 +1704,7 @@ Return t if any property was actually removed, nil otherwise.  */)
          else if (LENGTH (i) == len)
            {
              if (!modified && BUFFERP (object))
-               modify_region (object, start, end);
+               modify_text_properties (object, start, end);
              remove_properties (Qnil, properties, i, object);
              if (BUFFERP (object))
                signal_after_change (XINT (start), XINT (end) - XINT (start),
@@ -1706,7 +1717,7 @@ Return t if any property was actually removed, nil otherwise.  */)
              i = split_interval_left (i, len);
              copy_properties (unchanged, i);
              if (!modified && BUFFERP (object))
-               modify_region (object, start, end);
+               modify_text_properties (object, start, end);
              remove_properties (Qnil, properties, i, object);
              if (BUFFERP (object))
                signal_after_change (XINT (start), XINT (end) - XINT (start),
@@ -1717,7 +1728,7 @@ Return t if any property was actually removed, nil otherwise.  */)
       if (interval_has_some_properties_list (properties, i))
        {
          if (!modified && BUFFERP (object))
-           modify_region (object, start, end);
+           modify_text_properties (object, start, end);
          remove_properties (Qnil, properties, i, object);
          modified = 1;
        }