diff options
author | Chris Liddell <chris.liddell@artifex.com> | 2022-03-09 12:06:04 +0000 |
---|---|---|
committer | Chris Liddell <chris.liddell@artifex.com> | 2022-03-09 17:05:14 +0000 |
commit | 7a422ec782f6b5f6ea1664672cc436f19abb2234 (patch) | |
tree | 05fa25f118fe9611d0b334e296739805917ef0de | |
parent | e7c272a8b28dbbd30bd0d3c6bf078adc72f04897 (diff) | |
download | ghostpdl-7a422ec782f6b5f6ea1664672cc436f19abb2234.tar.gz |
Improve efficiency of pdfi_stream_to_buffer()
Still far from optimal, but when ascertaining the decompressed length of a
stream avoid "reading" the data, just check the available buffered bytes,
flush and refill the buffer. This should ensure we almost process the
maximum amount of bytes per iteration, regardless of the filter(s) in the
chain.
-rw-r--r-- | pdf/pdf_file.c | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/pdf/pdf_file.c b/pdf/pdf_file.c index 36e8ce376..1306f125b 100644 --- a/pdf/pdf_file.c +++ b/pdf/pdf_file.c @@ -1541,8 +1541,6 @@ pdfi_stream_to_buffer(pdf_context *ctx, pdf_stream *stream_obj, byte **buf, int6 byte *Buffer = NULL; int code = 0; int64_t buflen = 0; - int bytes; - char c; gs_offset_t savedoffset; pdf_c_stream *stream; bool filtered; @@ -1572,12 +1570,11 @@ pdfi_stream_to_buffer(pdf_context *ctx, pdf_stream *stream_obj, byte **buf, int6 if (code < 0) { goto exit; } - /* Find out how big it is */ - do { - bytes = sfread(&c, 1, 1, stream->s); - if (bytes > 0) - buflen++; - } while (bytes >= 0); + while (seofp(stream->s) != true && serrorp(stream->s) != true) { + sreset(stream->s); + s_process_read_buf(stream->s); + buflen += sbufavailable(stream->s); + } pdfi_close_file(ctx, stream); } else { buflen = pdfi_stream_length(ctx, stream_obj); |