summaryrefslogtreecommitdiff
path: root/src/alloc.c
diff options
context:
space:
mode:
authorAndrew Innes <andrewi@gnu.org>2001-12-05 21:39:01 +0000
committerAndrew Innes <andrewi@gnu.org>2001-12-05 21:39:01 +0000
commite0fead5d9f0536f821b870eea67c1a399111ceea (patch)
tree7a4fd0f53017acad1549c13854e3f90eb8654348 /src/alloc.c
parent8af5b8e71f0f24a486efd7b9e4713ce44629df2e (diff)
downloademacs-e0fead5d9f0536f821b870eea67c1a399111ceea.tar.gz
(Fgarbage_collect): Shrink buffer gaps that are
excessively large.
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 94ad4d59df7..6a47b872d23 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -1020,7 +1020,7 @@ make_number (n)
/* Lisp_Strings are allocated in string_block structures. When a new
string_block is allocated, all the Lisp_Strings it contains are
- added to a free-list stiing_free_list. When a new Lisp_String is
+ added to a free-list string_free_list. When a new Lisp_String is
needed, it is taken from that list. During the sweep phase of GC,
string_blocks that are entirely free are freed, except two which
we keep.
@@ -4096,6 +4096,24 @@ Garbage collection happens automatically if you cons more than
nextb->undo_list
= truncate_undo_list (nextb->undo_list, undo_limit,
undo_strong_limit);
+
+ /* Shrink buffer gaps, but skip indirect and dead buffers. */
+ if (nextb->base_buffer == 0 && !NILP (nextb->name))
+ {
+ /* 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, (nextb->text->z_byte / 10)));
+
+ if (nextb->text->gap_size > size)
+ {
+ struct buffer *save_current = current_buffer;
+ current_buffer = nextb;
+ make_gap (-(nextb->text->gap_size - size));
+ current_buffer = save_current;
+ }
+ }
+
nextb = nextb->next;
}
}