diff options
author | Ray Strode <rstrode@redhat.com> | 2023-12-10 21:59:47 -0500 |
---|---|---|
committer | Ray Strode <rstrode@redhat.com> | 2023-12-10 22:13:58 -0500 |
commit | 944f2210cda40a7c8063497c01deb93a055362b0 (patch) | |
tree | 0e4abb0b772ee22a78573ef27c923d8022589fbb | |
parent | 804a78860a133055aa2ad54523fa68c97cbfd84d (diff) |
ply-buffer: Make ply_buffer_clear fast if called multiple times in a row
ply_buffer_clear memsets over the entire allocation every time it is
run.
This commit makes it only clear the used part of the allocation.
-rw-r--r-- | src/libply/ply-buffer.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/libply/ply-buffer.c b/src/libply/ply-buffer.c index af37cbc9..0fa68d8a 100644 --- a/src/libply/ply-buffer.c +++ b/src/libply/ply-buffer.c @@ -275,6 +275,9 @@ ply_buffer_get_size (ply_buffer_t *buffer) void ply_buffer_clear (ply_buffer_t *buffer) { - memset (buffer->data, '\0', buffer->capacity); + if (buffer->size == 0) + return; + + memset (buffer->data, '\0', buffer->size); buffer->size = 0; } |