From 0a1c24eb9fe47ac2639c5933793e89563af07727 Mon Sep 17 00:00:00 2001 From: Miguel Portilla Date: Tue, 18 Oct 2016 16:23:23 -0400 Subject: [PATCH] Refactor read_size_helper --- CHANGELOG.md | 1 + include/beast/core/impl/basic_streambuf.ipp | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 04315bbc..7e66e6d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ * Add headers_parser * Engaged invokable is destructible * Improve websocket example in README.md +* Refactor read_size_helper API Changes: diff --git a/include/beast/core/impl/basic_streambuf.ipp b/include/beast/core/impl/basic_streambuf.ipp index c002af00..fb091496 100644 --- a/include/beast/core/impl/basic_streambuf.ipp +++ b/include/beast/core/impl/basic_streambuf.ipp @@ -856,10 +856,12 @@ read_size_helper(basic_streambuf< Allocator> const& streambuf, std::size_t max_size) { auto const avail = streambuf.capacity() - streambuf.size(); - if(avail == 0) - return std::min(max_size, - std::max(512, streambuf.alloc_size_)); - return std::min(max_size, avail); + if (avail > 0) + return std::min(avail, max_size); + constexpr std::size_t low = 512; + if (streambuf.alloc_size_ > low) + return std::min(max_size, streambuf.alloc_size_); + return std::min(max_size, low); } template