diff options
Diffstat (limited to 'fitz')
-rw-r--r-- | fitz/fitz.h | 1 | ||||
-rw-r--r-- | fitz/stm_buffer.c | 12 | ||||
-rw-r--r-- | fitz/stm_read.c | 1 |
3 files changed, 14 insertions, 0 deletions
diff --git a/fitz/fitz.h b/fitz/fitz.h index 856df7e5..ddffa181 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -784,6 +784,7 @@ void fz_drop_buffer(fz_context *ctx, fz_buffer *buf); void fz_resize_buffer(fz_context *ctx, fz_buffer *buf, int size); void fz_grow_buffer(fz_context *ctx, fz_buffer *buf); +void fz_trim_buffer(fz_context *ctx, fz_buffer *buf); /* * Resource store diff --git a/fitz/stm_buffer.c b/fitz/stm_buffer.c index 7f9d521d..d70118e1 100644 --- a/fitz/stm_buffer.c +++ b/fitz/stm_buffer.c @@ -28,7 +28,12 @@ fz_buffer * fz_keep_buffer(fz_context *ctx, fz_buffer *buf) { if (buf) + { + if (buf->refs == 1 && buf->cap > buf->len+1) + fz_resize_buffer(ctx, buf, buf->len); buf->refs ++; + } + return buf; } @@ -58,3 +63,10 @@ fz_grow_buffer(fz_context *ctx, fz_buffer *buf) { fz_resize_buffer(ctx, buf, (buf->cap * 3) / 2); } + +void +fz_trim_buffer(fz_context *ctx, fz_buffer *buf) +{ + if (buf->cap > buf->len+1) + fz_resize_buffer(ctx, buf, buf->len); +} diff --git a/fitz/stm_read.c b/fitz/stm_read.c index 81411c54..c2d375f3 100644 --- a/fitz/stm_read.c +++ b/fitz/stm_read.c @@ -125,6 +125,7 @@ fz_read_all(fz_stream *stm, int initial) fz_drop_buffer(ctx, buf); fz_rethrow(ctx); } + fz_trim_buffer(ctx, buf); return buf; } |