emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r111458: * lisp.h (make_gap_1): New p


From: Dmitry Antipov
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r111458: * lisp.h (make_gap_1): New prototype.
Date: Wed, 09 Jan 2013 17:50:22 +0400
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 111458
committer: Dmitry Antipov <address@hidden>
branch nick: trunk
timestamp: Wed 2013-01-09 17:50:22 +0400
message:
  * lisp.h (make_gap_1): New prototype.
  * buffer.h (GAP_BYTES_DFL, GAP_BYTES_MIN): New macros for the special
  gap size values.
  * editfns.c (Fbuffer_size): Rename from Fbufsize to fit the common
  naming convention.
  (syms_of_editfns): Adjust defsubr.  Drop commented-out obsolete code.
  * insdel.c (make_gap_larger): Use GAP_BYTES_DFL.
  (make_gap_smaller): Use GAP_BYTES_MIN.  Adjust comment.
  (make_gap_1): New function to adjust the gap of any buffer.
  * coding.c (coding_alloc_by_making_gap): Use it.
  * buffer.c (compact_buffer): Likewise.  Use BUF_Z_BYTE, BUF_GAP_SIZE,
  GAP_BYTES_DFL and GAP_BYTES_MIN.  Adjust comment.
modified:
  src/ChangeLog
  src/buffer.c
  src/buffer.h
  src/coding.c
  src/editfns.c
  src/insdel.c
  src/lisp.h
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2013-01-08 23:50:40 +0000
+++ b/src/ChangeLog     2013-01-09 13:50:22 +0000
@@ -1,3 +1,18 @@
+2013-01-09  Dmitry Antipov  <address@hidden>
+
+       * lisp.h (make_gap_1): New prototype.
+       * buffer.h (GAP_BYTES_DFL, GAP_BYTES_MIN): New macros for the special
+       gap size values.
+       * editfns.c (Fbuffer_size): Rename from Fbufsize to fit the common
+       naming convention.
+       (syms_of_editfns): Adjust defsubr.  Drop commented-out obsolete code.
+       * insdel.c (make_gap_larger): Use GAP_BYTES_DFL.
+       (make_gap_smaller): Use GAP_BYTES_MIN.  Adjust comment.
+       (make_gap_1): New function to adjust the gap of any buffer.
+       * coding.c (coding_alloc_by_making_gap): Use it.
+       * buffer.c (compact_buffer): Likewise.  Use BUF_Z_BYTE, BUF_GAP_SIZE,
+       GAP_BYTES_DFL and GAP_BYTES_MIN.  Adjust comment.
+
 2013-01-08  Juri Linkov  <address@hidden>
 
        * xfaces.c (tty_supports_face_attributes_p): Return 0 for the case

=== modified file 'src/buffer.c'
--- a/src/buffer.c      2013-01-02 16:13:04 +0000
+++ b/src/buffer.c      2013-01-09 13:50:22 +0000
@@ -1682,17 +1682,13 @@
       if (!buffer->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, (buffer->text->z_byte / 10)));
-
-         if (buffer->text->gap_size > size)
-           {
-             struct buffer *save_current = current_buffer;
-             current_buffer = buffer;
-             make_gap (-(buffer->text->gap_size - size));
-             current_buffer = save_current;
-           }
+            size, or larger than GAP_BYTES_DFL bytes, then shrink it
+            accordingly.  Keep a minimum size of GAP_BYTES_MIN bytes.  */
+         ptrdiff_t size = clip_to_bounds (GAP_BYTES_MIN,
+                                          BUF_Z_BYTE (buffer) / 10,
+                                          GAP_BYTES_DFL);
+         if (BUF_GAP_SIZE (buffer) > size)
+           make_gap_1 (buffer, -(BUF_GAP_SIZE (buffer) - size));
        }
       BUF_COMPACT (buffer) = BUF_MODIFF (buffer);
     }

=== modified file 'src/buffer.h'
--- a/src/buffer.h      2013-01-02 16:13:04 +0000
+++ b/src/buffer.h      2013-01-09 13:50:22 +0000
@@ -320,6 +320,16 @@
 #define BUF_BYTES_MAX \
   (ptrdiff_t) min (MOST_POSITIVE_FIXNUM - 1, min (SIZE_MAX, PTRDIFF_MAX))
 
+/* Maximum gap size after compact_buffer, in bytes.  Also
+   used in make_gap_larger to get some extra reserved space.  */
+
+#define GAP_BYTES_DFL 2000
+
+/* Minimum gap size after compact_buffer, in bytes.  Also
+   used in make_gap_smaller to avoid too small gap size.  */
+
+#define GAP_BYTES_MIN 20
+
 /* Return the address of byte position N in current buffer.  */
 
 #define BYTE_POS_ADDR(n) \

=== modified file 'src/coding.c'
--- a/src/coding.c      2013-01-02 16:13:04 +0000
+++ b/src/coding.c      2013-01-09 13:50:22 +0000
@@ -1049,14 +1049,7 @@
       GPT -= gap_head_used, GPT_BYTE -= gap_head_used;
     }
   else
-    {
-      Lisp_Object this_buffer;
-
-      this_buffer = Fcurrent_buffer ();
-      set_buffer_internal (XBUFFER (coding->dst_object));
-      make_gap (bytes);
-      set_buffer_internal (XBUFFER (this_buffer));
-    }
+    make_gap_1 (XBUFFER (coding->dst_object), bytes);
 }
 
 

=== modified file 'src/editfns.c'
--- a/src/editfns.c     2013-01-02 16:13:04 +0000
+++ b/src/editfns.c     2013-01-09 13:50:22 +0000
@@ -968,7 +968,7 @@
   return unbind_to (count, Fprogn (args));
 }
 
-DEFUN ("buffer-size", Fbufsize, Sbufsize, 0, 1, 0,
+DEFUN ("buffer-size", Fbuffer_size, Sbuffer_size, 0, 1, 0,
        doc: /* Return the number of characters in the current buffer.
 If BUFFER, return the number of characters in that buffer instead.  */)
   (Lisp_Object buffer)
@@ -4883,12 +4883,10 @@
   defsubr (&Sline_beginning_position);
   defsubr (&Sline_end_position);
 
-/*  defsubr (&Smark); */
-/*  defsubr (&Sset_mark); */
   defsubr (&Ssave_excursion);
   defsubr (&Ssave_current_buffer);
 
-  defsubr (&Sbufsize);
+  defsubr (&Sbuffer_size);
   defsubr (&Spoint_max);
   defsubr (&Spoint_min);
   defsubr (&Spoint_min_marker);

=== modified file 'src/insdel.c'
--- a/src/insdel.c      2013-01-02 16:13:04 +0000
+++ b/src/insdel.c      2013-01-09 13:50:22 +0000
@@ -388,14 +388,13 @@
   ptrdiff_t real_gap_loc_byte;
   ptrdiff_t old_gap_size;
   ptrdiff_t current_size = Z_BYTE - BEG_BYTE + GAP_SIZE;
-  enum { enough_for_a_while = 2000 };
 
   if (BUF_BYTES_MAX - current_size < nbytes_added)
     buffer_overflow ();
 
   /* If we have to get more space, get enough to last a while;
      but do not exceed the maximum buffer size.  */
-  nbytes_added = min (nbytes_added + enough_for_a_while,
+  nbytes_added = min (nbytes_added + GAP_BYTES_DFL,
                      BUF_BYTES_MAX - current_size);
 
   enlarge_buffer_text (current_buffer, nbytes_added);
@@ -443,9 +442,9 @@
   ptrdiff_t real_beg_unchanged;
   ptrdiff_t new_gap_size;
 
-  /* Make sure the gap is at least 20 bytes.  */
-  if (GAP_SIZE - nbytes_removed < 20)
-    nbytes_removed = GAP_SIZE - 20;
+  /* Make sure the gap is at least GAP_BYTES_MIN bytes.  */
+  if (GAP_SIZE - nbytes_removed < GAP_BYTES_MIN)
+    nbytes_removed = GAP_SIZE - GAP_BYTES_MIN;
 
   /* Prevent quitting in move_gap.  */
   tem = Vinhibit_quit;
@@ -500,7 +499,20 @@
     make_gap_smaller (-nbytes_added);
 #endif
 }
-
+
+/* Add NBYTES to B's gap.  It's enough to temporarily
+   fake current_buffer and avoid real switch to B.  */
+
+void
+make_gap_1 (struct buffer *b, ptrdiff_t nbytes)
+{
+  struct buffer *oldb = current_buffer;
+
+  current_buffer = b;
+  make_gap (nbytes);
+  current_buffer = oldb;
+}
+
 /* Copy NBYTES bytes of text from FROM_ADDR to TO_ADDR.
    FROM_MULTIBYTE says whether the incoming text is multibyte.
    TO_MULTIBYTE says whether to store the text as multibyte.

=== modified file 'src/lisp.h'
--- a/src/lisp.h        2013-01-02 16:13:04 +0000
+++ b/src/lisp.h        2013-01-09 13:50:22 +0000
@@ -2778,6 +2778,7 @@
 extern void move_gap_both (ptrdiff_t, ptrdiff_t);
 extern _Noreturn void buffer_overflow (void);
 extern void make_gap (ptrdiff_t);
+extern void make_gap_1 (struct buffer *, ptrdiff_t);
 extern ptrdiff_t copy_text (const unsigned char *, unsigned char *,
                            ptrdiff_t, bool, bool);
 extern int count_combining_before (const unsigned char *,


reply via email to

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