Correct and simplify buf_shrink logic

svn:r4167
This commit is contained in:
Nick Mathewson 2005-05-02 23:36:13 +00:00
parent d6a6c8785b
commit ad547cbb8c

View File

@ -249,13 +249,13 @@ buf_shrink(buf_t *buf)
{
size_t new_len;
if (buf->highwater >= (buf->len<<2) && buf->len > MIN_LAZY_SHRINK_SIZE*2)
return;
new_len = (buf->len>>1);
new_len = buf->len;
while (buf->highwater < (new_len>>2) && new_len > MIN_LAZY_SHRINK_SIZE*2)
new_len >>= 1;
if (new_len == buf->len)
return;
log_fn(LOG_DEBUG,"Shrinking buffer from %d to %d bytes.",
(int)buf->len, (int)new_len);
buf_resize(buf, new_len);