diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2016-02-12 12:06:52 +0100 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2016-02-12 12:07:06 +0100 |
commit | 91d33255793adf58816308c97559c22d0c26cc78 (patch) | |
tree | e8a2ca68e40b4ae6ba2049d3641f120f3aa5347d | |
parent | ec6e25693e921077d76868c5c137b9ff17ad4079 (diff) | |
download | mupdf-91d33255793adf58816308c97559c22d0c26cc78.tar.xz |
Improve performance of fz_write of single bytes.
Use putc for single byte writes instead of fwrite.
-rw-r--r-- | source/fitz/output.c | 16 |
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; } |