summaryrefslogtreecommitdiff
path: root/source/fitz/output.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2016-02-12 12:06:52 +0100
committerTor Andersson <tor.andersson@artifex.com>2016-02-12 12:07:06 +0100
commit91d33255793adf58816308c97559c22d0c26cc78 (patch)
treee8a2ca68e40b4ae6ba2049d3641f120f3aa5347d /source/fitz/output.c
parentec6e25693e921077d76868c5c137b9ff17ad4079 (diff)
downloadmupdf-91d33255793adf58816308c97559c22d0c26cc78.tar.xz
Improve performance of fz_write of single bytes.
Use putc for single byte writes instead of fwrite.
Diffstat (limited to 'source/fitz/output.c')
-rw-r--r--source/fitz/output.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/source/fitz/output.c b/source/fitz/output.c
index b3efb121..3f2dde29 100644
--- a/source/fitz/output.c
+++ b/source/fitz/output.c
@@ -17,6 +17,20 @@ file_write(fz_context *ctx, void *opaque, const void *buffer, int count)
if (count < 0)
return 0;
+
+ if (count == 1)
+ {
+ int x = putc(((unsigned char*)buffer)[0], file);
+ if (x == EOF)
+ {
+ if (ferror(file))
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot fwrite: %s", strerror(errno));
+ else
+ return 0;
+ }
+ return 1;
+ }
+
n = fwrite(buffer, 1, count, file);
if (n < (size_t)count && ferror(file))
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot fwrite: %s", strerror(errno));
@@ -88,7 +102,7 @@ static int
buffer_write(fz_context *ctx, void *opaque, const void *data, int len)
{
fz_buffer *buffer = opaque;
- fz_write_buffer(ctx, buffer, (unsigned char *)data, len);
+ fz_write_buffer(ctx, buffer, data, len);
return len;
}