From eefd727851555237c7bc205b7ad255c50ba3fff9 Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Wed, 9 Jan 2013 17:50:22 +0400 Subject: * 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. --- src/buffer.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'src/buffer.c') diff --git a/src/buffer.c b/src/buffer.c index 5999fcb7e7d..51c4d9c71da 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1682,17 +1682,13 @@ compact_buffer (struct buffer *buffer) 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); } -- cgit v1.2.1