maintain own free list of buffer headers

This commit is contained in:
ceriel 1990-01-29 11:41:37 +00:00
parent 343dbb810f
commit 0c4835caf3

View file

@ -87,7 +87,7 @@ struct INP_i_buf {
# endif not INP_READ_IN_ONE # endif not INP_READ_IN_ONE
char *_ipp; char *_ipp;
INP_PRIVATE struct INP_buffer_header *INP_head; INP_PRIVATE struct INP_buffer_header *INP_head, *INP_free;
#ifdef INP_READ_IN_ONE #ifdef INP_READ_IN_ONE
/* INP_rdfile() creates a buffer in which the text of the file /* INP_rdfile() creates a buffer in which the text of the file
@ -162,7 +162,9 @@ INP_push_bh()
bh->bh_i = INP_VAR; bh->bh_i = INP_VAR;
#endif INP_TYPE #endif INP_TYPE
} }
if (!(bh = (struct INP_buffer_header *)malloc(sizeof(struct INP_buffer_header)))) return 0; bh = INP_free;
if (bh) INP_free = bh->bh_next;
else if (!(bh = (struct INP_buffer_header *)malloc(sizeof(struct INP_buffer_header)))) return 0;
bh->bh_next = INP_head; bh->bh_next = INP_head;
bh->bh_eofreturned = 0; bh->bh_eofreturned = 0;
INP_head = bh; INP_head = bh;
@ -180,7 +182,8 @@ INP_pop_bh()
bh = bh->bh_next; bh = bh->bh_next;
free((char *) INP_head); INP_head->bh_next = INP_free;
INP_free = INP_head;
INP_head = bh; INP_head = bh;
if (!bh) { /* no more entries */ if (!bh) { /* no more entries */