diff options
| author | Dmitry Antipov | 2012-07-19 07:55:59 +0400 |
|---|---|---|
| committer | Dmitry Antipov | 2012-07-19 07:55:59 +0400 |
| commit | d17337e501a189c1d46f758e10c6c2842cafff17 (patch) | |
| tree | 152a6d615152a9fc12d40e131ebb1886d8972593 /src/alloc.c | |
| parent | 1d29cc7da73dde538c97d029723b8a5a1be6cea1 (diff) | |
| download | emacs-d17337e501a189c1d46f758e10c6c2842cafff17.tar.gz emacs-d17337e501a189c1d46f758e10c6c2842cafff17.zip | |
New macro to iterate over all buffers, miscellaneous cleanups.
* lisp.h (all_buffers): Remove declaration.
* buffer.h (all_buffers): Add declaration, with comment.
(for_each_buffer): New macro.
* alloc.c (Fgarbage_collect, mark_object): Use it.
* buffer.c (Fkill_buffer, Fbuffer_swap_text, Fset_buffer_multibyte)
(init_buffer): Likewise.
* data.c (Fset_default): Likewise.
* coding.c (code_conversion_restore): Remove redundant check
for dead buffer.
* buffer.c (Fkill_buffer): Likewise. Remove obsolete comment.
Diffstat (limited to 'src/alloc.c')
| -rw-r--r-- | src/alloc.c | 146 |
1 files changed, 68 insertions, 78 deletions
diff --git a/src/alloc.c b/src/alloc.c index a6980e867a7..166f5b72449 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -5392,6 +5392,7 @@ See Info node `(elisp)Garbage Collection'. */) | |||
| 5392 | (void) | 5392 | (void) |
| 5393 | { | 5393 | { |
| 5394 | register struct specbinding *bind; | 5394 | register struct specbinding *bind; |
| 5395 | register struct buffer *nextb; | ||
| 5395 | char stack_top_variable; | 5396 | char stack_top_variable; |
| 5396 | ptrdiff_t i; | 5397 | ptrdiff_t i; |
| 5397 | int message_p; | 5398 | int message_p; |
| @@ -5411,40 +5412,34 @@ See Info node `(elisp)Garbage Collection'. */) | |||
| 5411 | 5412 | ||
| 5412 | /* Don't keep undo information around forever. | 5413 | /* Don't keep undo information around forever. |
| 5413 | Do this early on, so it is no problem if the user quits. */ | 5414 | Do this early on, so it is no problem if the user quits. */ |
| 5414 | { | 5415 | for_each_buffer (nextb) |
| 5415 | register struct buffer *nextb = all_buffers; | 5416 | { |
| 5416 | 5417 | /* If a buffer's undo list is Qt, that means that undo is | |
| 5417 | while (nextb) | 5418 | turned off in that buffer. Calling truncate_undo_list on |
| 5418 | { | 5419 | Qt tends to return NULL, which effectively turns undo back on. |
| 5419 | /* If a buffer's undo list is Qt, that means that undo is | 5420 | So don't call truncate_undo_list if undo_list is Qt. */ |
| 5420 | turned off in that buffer. Calling truncate_undo_list on | 5421 | if (! NILP (nextb->BUFFER_INTERNAL_FIELD (name)) |
| 5421 | Qt tends to return NULL, which effectively turns undo back on. | 5422 | && ! EQ (nextb->BUFFER_INTERNAL_FIELD (undo_list), Qt)) |
| 5422 | So don't call truncate_undo_list if undo_list is Qt. */ | 5423 | truncate_undo_list (nextb); |
| 5423 | if (! NILP (nextb->BUFFER_INTERNAL_FIELD (name)) | 5424 | |
| 5424 | && ! EQ (nextb->BUFFER_INTERNAL_FIELD (undo_list), Qt)) | 5425 | /* Shrink buffer gaps, but skip indirect and dead buffers. */ |
| 5425 | truncate_undo_list (nextb); | 5426 | if (nextb->base_buffer == 0 && !NILP (nextb->BUFFER_INTERNAL_FIELD (name)) |
| 5426 | 5427 | && ! nextb->text->inhibit_shrinking) | |
| 5427 | /* Shrink buffer gaps, but skip indirect and dead buffers. */ | 5428 | { |
| 5428 | if (nextb->base_buffer == 0 && !NILP (nextb->BUFFER_INTERNAL_FIELD (name)) | 5429 | /* If a buffer's gap size is more than 10% of the buffer |
| 5429 | && ! nextb->text->inhibit_shrinking) | 5430 | size, or larger than 2000 bytes, then shrink it |
| 5430 | { | 5431 | accordingly. Keep a minimum size of 20 bytes. */ |
| 5431 | /* If a buffer's gap size is more than 10% of the buffer | 5432 | int size = min (2000, max (20, (nextb->text->z_byte / 10))); |
| 5432 | size, or larger than 2000 bytes, then shrink it | ||
| 5433 | accordingly. Keep a minimum size of 20 bytes. */ | ||
| 5434 | int size = min (2000, max (20, (nextb->text->z_byte / 10))); | ||
| 5435 | |||
| 5436 | if (nextb->text->gap_size > size) | ||
| 5437 | { | ||
| 5438 | struct buffer *save_current = current_buffer; | ||
| 5439 | current_buffer = nextb; | ||
| 5440 | make_gap (-(nextb->text->gap_size - size)); | ||
| 5441 | current_buffer = save_current; | ||
| 5442 | } | ||
| 5443 | } | ||
| 5444 | 5433 | ||
| 5445 | nextb = nextb->header.next.buffer; | 5434 | if (nextb->text->gap_size > size) |
| 5446 | } | 5435 | { |
| 5447 | } | 5436 | struct buffer *save_current = current_buffer; |
| 5437 | current_buffer = nextb; | ||
| 5438 | make_gap (-(nextb->text->gap_size - size)); | ||
| 5439 | current_buffer = save_current; | ||
| 5440 | } | ||
| 5441 | } | ||
| 5442 | } | ||
| 5448 | 5443 | ||
| 5449 | t1 = current_emacs_time (); | 5444 | t1 = current_emacs_time (); |
| 5450 | 5445 | ||
| @@ -5558,48 +5553,42 @@ See Info node `(elisp)Garbage Collection'. */) | |||
| 5558 | Look thru every buffer's undo list | 5553 | Look thru every buffer's undo list |
| 5559 | for elements that update markers that were not marked, | 5554 | for elements that update markers that were not marked, |
| 5560 | and delete them. */ | 5555 | and delete them. */ |
| 5561 | { | 5556 | for_each_buffer (nextb) |
| 5562 | register struct buffer *nextb = all_buffers; | 5557 | { |
| 5563 | 5558 | /* If a buffer's undo list is Qt, that means that undo is | |
| 5564 | while (nextb) | 5559 | turned off in that buffer. Calling truncate_undo_list on |
| 5565 | { | 5560 | Qt tends to return NULL, which effectively turns undo back on. |
| 5566 | /* If a buffer's undo list is Qt, that means that undo is | 5561 | So don't call truncate_undo_list if undo_list is Qt. */ |
| 5567 | turned off in that buffer. Calling truncate_undo_list on | 5562 | if (! EQ (nextb->BUFFER_INTERNAL_FIELD (undo_list), Qt)) |
| 5568 | Qt tends to return NULL, which effectively turns undo back on. | 5563 | { |
| 5569 | So don't call truncate_undo_list if undo_list is Qt. */ | 5564 | Lisp_Object tail, prev; |
| 5570 | if (! EQ (nextb->BUFFER_INTERNAL_FIELD (undo_list), Qt)) | 5565 | tail = nextb->BUFFER_INTERNAL_FIELD (undo_list); |
| 5571 | { | 5566 | prev = Qnil; |
| 5572 | Lisp_Object tail, prev; | 5567 | while (CONSP (tail)) |
| 5573 | tail = nextb->BUFFER_INTERNAL_FIELD (undo_list); | 5568 | { |
| 5574 | prev = Qnil; | 5569 | if (CONSP (XCAR (tail)) |
| 5575 | while (CONSP (tail)) | 5570 | && MARKERP (XCAR (XCAR (tail))) |
| 5576 | { | 5571 | && !XMARKER (XCAR (XCAR (tail)))->gcmarkbit) |
| 5577 | if (CONSP (XCAR (tail)) | 5572 | { |
| 5578 | && MARKERP (XCAR (XCAR (tail))) | 5573 | if (NILP (prev)) |
| 5579 | && !XMARKER (XCAR (XCAR (tail)))->gcmarkbit) | 5574 | nextb->BUFFER_INTERNAL_FIELD (undo_list) = tail = XCDR (tail); |
| 5580 | { | 5575 | else |
| 5581 | if (NILP (prev)) | 5576 | { |
| 5582 | nextb->BUFFER_INTERNAL_FIELD (undo_list) = tail = XCDR (tail); | 5577 | tail = XCDR (tail); |
| 5583 | else | 5578 | XSETCDR (prev, tail); |
| 5584 | { | 5579 | } |
| 5585 | tail = XCDR (tail); | 5580 | } |
| 5586 | XSETCDR (prev, tail); | 5581 | else |
| 5587 | } | 5582 | { |
| 5588 | } | 5583 | prev = tail; |
| 5589 | else | 5584 | tail = XCDR (tail); |
| 5590 | { | 5585 | } |
| 5591 | prev = tail; | 5586 | } |
| 5592 | tail = XCDR (tail); | 5587 | } |
| 5593 | } | 5588 | /* Now that we have stripped the elements that need not be in the |
| 5594 | } | 5589 | undo_list any more, we can finally mark the list. */ |
| 5595 | } | 5590 | mark_object (nextb->BUFFER_INTERNAL_FIELD (undo_list)); |
| 5596 | /* Now that we have stripped the elements that need not be in the | 5591 | } |
| 5597 | undo_list any more, we can finally mark the list. */ | ||
| 5598 | mark_object (nextb->BUFFER_INTERNAL_FIELD (undo_list)); | ||
| 5599 | |||
| 5600 | nextb = nextb->header.next.buffer; | ||
| 5601 | } | ||
| 5602 | } | ||
| 5603 | 5592 | ||
| 5604 | gc_sweep (); | 5593 | gc_sweep (); |
| 5605 | 5594 | ||
| @@ -5987,9 +5976,10 @@ mark_object (Lisp_Object arg) | |||
| 5987 | #ifdef GC_CHECK_MARKED_OBJECTS | 5976 | #ifdef GC_CHECK_MARKED_OBJECTS |
| 5988 | if (po != &buffer_defaults && po != &buffer_local_symbols) | 5977 | if (po != &buffer_defaults && po != &buffer_local_symbols) |
| 5989 | { | 5978 | { |
| 5990 | struct buffer *b = all_buffers; | 5979 | struct buffer *b; |
| 5991 | for (; b && b != po; b = b->header.next.buffer) | 5980 | for_each_buffer (b) |
| 5992 | ; | 5981 | if (b == po) |
| 5982 | break; | ||
| 5993 | if (b == NULL) | 5983 | if (b == NULL) |
| 5994 | abort (); | 5984 | abort (); |
| 5995 | } | 5985 | } |