diff options
| author | Jim Blandy | 1992-09-09 00:05:42 +0000 |
|---|---|---|
| committer | Jim Blandy | 1992-09-09 00:05:42 +0000 |
| commit | 16a5c72935c9b945d083e6e7397033182ece3357 (patch) | |
| tree | 71df8225634f0a71f7cf02f3d09c74dc40073394 /src/ralloc.c | |
| parent | 6cf420725b8c77321b37c858f7b698bd76224851 (diff) | |
| download | emacs-16a5c72935c9b945d083e6e7397033182ece3357.tar.gz emacs-16a5c72935c9b945d083e6e7397033182ece3357.zip | |
* ralloc.c (r_re_alloc): Instead of allocating a new bloc at the
end of the heap, copying the data to it, and then freeing the
original bloc, just expand the original block. This saves a copy
and a call to sbrk, and also removes the large spike in memory
allocation that would occur when resizing large buffers. And it's
less code.
Diffstat (limited to 'src/ralloc.c')
| -rw-r--r-- | src/ralloc.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/ralloc.c b/src/ralloc.c index d06472f8ea9..fb8325c04de 100644 --- a/src/ralloc.c +++ b/src/ralloc.c | |||
| @@ -376,10 +376,10 @@ r_alloc_free (ptr) | |||
| 376 | free_bloc (dead_bloc); | 376 | free_bloc (dead_bloc); |
| 377 | } | 377 | } |
| 378 | 378 | ||
| 379 | /* Given a pointer at address PTR to relocatable data, resize it | 379 | /* Given a pointer at address PTR to relocatable data, resize it to SIZE. |
| 380 | to SIZE. This is done by obtaining a new block and freeing the | 380 | This is done by shifting all blocks above this one up in memory, |
| 381 | old, unless SIZE is less than or equal to the current bloc size, | 381 | unless SIZE is less than or equal to the current bloc size, in |
| 382 | in which case nothing happens and the current value is returned. | 382 | which case nothing happens and the current value is returned. |
| 383 | 383 | ||
| 384 | The contents of PTR is changed to reflect the new bloc, and this | 384 | The contents of PTR is changed to reflect the new bloc, and this |
| 385 | value is returned. */ | 385 | value is returned. */ |
| @@ -389,22 +389,24 @@ r_re_alloc (ptr, size) | |||
| 389 | POINTER *ptr; | 389 | POINTER *ptr; |
| 390 | SIZE size; | 390 | SIZE size; |
| 391 | { | 391 | { |
| 392 | register bloc_ptr old_bloc, new_bloc; | 392 | register bloc_ptr bloc; |
| 393 | 393 | ||
| 394 | old_bloc = find_bloc (ptr); | 394 | bloc = find_bloc (ptr); |
| 395 | if (old_bloc == NIL_BLOC) | 395 | if (bloc == NIL_BLOC) |
| 396 | abort (); | 396 | abort (); |
| 397 | 397 | ||
| 398 | if (size <= old_bloc->size) | 398 | if (size <= bloc->size) |
| 399 | /* Wouldn't it be useful to actually resize the bloc here? */ | 399 | /* Wouldn't it be useful to actually resize the bloc here? */ |
| 400 | return *ptr; | 400 | return *ptr; |
| 401 | 401 | ||
| 402 | new_bloc = get_bloc (size); | 402 | obtain (size - bloc->size); |
| 403 | new_bloc->variable = ptr; | 403 | relocate_some_blocs (bloc->next, bloc->data + size); |
| 404 | safe_bcopy (old_bloc->data, new_bloc->data, old_bloc->size); | ||
| 405 | *ptr = new_bloc->data; | ||
| 406 | 404 | ||
| 407 | free_bloc (old_bloc); | 405 | /* Zero out the new space in the bloc, to help catch bugs faster. */ |
| 406 | bzero (bloc->data + bloc->size, size - bloc->size); | ||
| 407 | |||
| 408 | /* Indicate that this block has a new size. */ | ||
| 409 | bloc->size = size; | ||
| 408 | 410 | ||
| 409 | return *ptr; | 411 | return *ptr; |
| 410 | } | 412 | } |