diff options
author | Robin Watts <robin.watts@artifex.com> | 2012-02-23 11:07:15 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2012-02-25 08:14:40 -0800 |
commit | d28129c2ff6a78c50877426f90167d63334ab18a (patch) | |
tree | a6cfaf83edf1af26359516cc99c8da366fa41390 | |
parent | f86c02284c259b9034f324dffe76969efa8b2e42 (diff) | |
download | mupdf-d28129c2ff6a78c50877426f90167d63334ab18a.tar.xz |
Add fz_trim_buffer function, and call it.
Remove stray space at the end of buffers.
-rw-r--r-- | fitz/fitz.h | 1 | ||||
-rw-r--r-- | fitz/stm_buffer.c | 12 | ||||
-rw-r--r-- | fitz/stm_read.c | 1 | ||||
-rw-r--r-- | pdf/pdf_page.c | 1 |
4 files changed, 15 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; } diff --git a/pdf/pdf_page.c b/pdf/pdf_page.c index f2bf713e..de8e7051 100644 --- a/pdf/pdf_page.c +++ b/pdf/pdf_page.c @@ -277,6 +277,7 @@ pdf_load_page_contents_array(pdf_document *xref, fz_obj *list) fz_drop_buffer(ctx, big); fz_throw(ctx, "cannot load content stream"); } + fz_trim_buffer(ctx, big); return big; } |