summaryrefslogtreecommitdiffstats
path: root/chksum.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-07-04 07:20:40 -0700
committerKaz Kylheku <kaz@kylheku.com>2019-07-04 07:20:40 -0700
commitf47ad62b88bcff263c3f14b3107968efffd8378a (patch)
tree730934d21b4c11354d138530370d499e78f1458a /chksum.c
parent1a80dcbb725b8197369048a3eff4492e9797567f (diff)
downloadtxr-f47ad62b88bcff263c3f14b3107968efffd8378a.tar.gz
txr-f47ad62b88bcff263c3f14b3107968efffd8378a.tar.bz2
txr-f47ad62b88bcff263c3f14b3107968efffd8378a.zip
sha256: recycle I/O buffer used in stream hash.
* chksum.c (sha256_stream): Use iobuf_get and iobuf_put. * gc.c (gc): Do not mark the list of recycled buffers; just consider them to be garbage and clear the list, like we do with recycled conses via rcyc_empty. * stream.c (iobuf_free_list): New static variable. (iobuf_get, iobuf_put, iobuf_list_empty): New functions. * stream.h (iobuf_get, iobuf_put, iobuf_list_empty): Declared.
Diffstat (limited to 'chksum.c')
-rw-r--r--chksum.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/chksum.c b/chksum.c
index 588bdf92..1863ba47 100644
--- a/chksum.c
+++ b/chksum.c
@@ -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);
}