Use max_blen instead of constant

This commit is contained in:
Abdelhakim Qbaich 2026-04-04 16:48:30 -04:00
parent c3810949f0
commit 0c24c83535
5 changed files with 28 additions and 4 deletions

View File

@ -206,7 +206,7 @@ OASISReader::get_str (std::string &s)
size_t l = 0;
get_size (l);
const size_t chunk_size = 32767;
const size_t chunk_size = m_stream.max_blen ();
if (l <= chunk_size) {
char *b = (char *) m_stream.get (l);
@ -3677,3 +3677,4 @@ OASISReader::do_read_cell (db::cell_index_type cell_index, db::Layout &layout)
}
}

View File

@ -246,7 +246,7 @@ InflateFilter::~InflateFilter ()
const char *
InflateFilter::get (size_t n)
{
tl_assert (n < sizeof (m_buffer) / 2);
tl_assert (n <= max_blen ());
while ((m_b_insert + sizeof (m_buffer) - m_b_read) % sizeof (m_buffer) < n) {
if (! process ()) {
@ -558,4 +558,3 @@ DeflateFilter::flush ()
}
}

View File

@ -211,10 +211,18 @@ public:
* @brief Get the next byte(s)
*
* This method returns a contiguous block of decoded bytes with the given length.
* The maximum size of the block available is half the buffer size.
* The maximum size of the block available is given by max_blen().
*/
const char *get (size_t n);
/**
* @brief Obtain the maximum number of bytes available for a single get() call
*/
size_t max_blen () const
{
return sizeof (m_buffer) / 2 - 1;
}
/**
* @brief Undo the last "get" operation
*

View File

@ -604,6 +604,12 @@ InputStream::get (size_t n, bool bypass_inflate)
}
}
size_t
InputStream::max_blen () const
{
return mp_inflate ? mp_inflate->max_blen () : std::numeric_limits<size_t>::max ();
}
void
InputStream::unget (size_t n)
{

View File

@ -33,6 +33,7 @@
#include <sstream>
#include <cstdio>
#include <cstring>
#include <limits>
namespace tl
@ -498,6 +499,15 @@ public:
return m_blen;
}
/**
* @brief Obtain the maximum number of bytes available for a single get() call
*
* This is an API limit, not the actual number of bytes available right now.
* For inflating streams this reports the maximum contiguous chunk size the
* inflating filter can provide in one get() call.
*/
size_t max_blen () const;
/**
* @brief Get the source specification (the file name)
*