diff options
-rw-r--r-- | chksum.c | 5 | ||||
-rw-r--r-- | gc.c | 1 | ||||
-rw-r--r-- | stream.c | 27 | ||||
-rw-r--r-- | stream.h | 4 |
4 files changed, 34 insertions, 3 deletions
@@ -51,8 +51,8 @@ val sha256_stream(val stream, val nbytes) { SHA256_t s256; unsigned char *hash = chk_malloc(SHA256_DIGEST_LENGTH); - val bfsz = num_fast(BUFSIZ); - val buf = make_buf(bfsz, nil, nil); + val buf = iobuf_get(); + val bfsz = length_buf(buf); SHA256_init(&s256); if (null_or_missing_p(nbytes)) { @@ -88,6 +88,7 @@ val sha256_stream(val stream, val nbytes) } SHA256_final(&s256, hash); + iobuf_put(buf); return make_borrowed_buf(num_fast(SHA256_DIGEST_LENGTH), hash); } @@ -754,6 +754,7 @@ void gc(void) save_context(mc); gc_enabled = 0; rcyc_empty(); + iobuf_list_empty(); mark(&mc, &gc_stack_top); hash_process_weak(); prepare_finals(); @@ -4605,6 +4605,33 @@ val make_byte_input_stream(val obj) } } +static val iobuf_free_list; + +val iobuf_get(void) +{ + val buf = iobuf_free_list; + + if (buf) { + val next = buf->b.len; + buf->b.len = buf->b.size; + iobuf_free_list = next; + return buf; + } else { + return make_buf(num_fast(BUFSIZ), nil, nil); + } +} + +void iobuf_put(val buf) +{ + buf->b.len = iobuf_free_list; + iobuf_free_list = buf; +} + +void iobuf_list_empty(void) +{ + iobuf_free_list = nil; +} + void stream_init(void) { prot1(&ap_regex); @@ -240,5 +240,7 @@ val base_name(val path); val dir_name(val path); val path_cat(val dir_name, val base_name); val make_byte_input_stream(val obj); - +val iobuf_get(void); +void iobuf_put(val buf); +void iobuf_list_empty(void); void stream_init(void); |