diff options
Diffstat (limited to 'src/pdf_bridge.c')
| -rw-r--r-- | src/pdf_bridge.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/pdf_bridge.c b/src/pdf_bridge.c index 57711245..a35dfa71 100644 --- a/src/pdf_bridge.c +++ b/src/pdf_bridge.c @@ -353,6 +353,20 @@ pardes_pdf_grown_capacity(size_t current, size_t needed, size_t maximum) return capacity; } +/* + * MuPDF's first page lookup loads a map of EVERY page object (the page tree + * flattened, each page's dictionary parsed out of its object stream): the + * SDM's 5363 took 735 ms in Debug, the first page's size alone. Walking the + * tree by its /Count for each lookup loads only the nodes on the way. + */ +static void +pardes_pdf_walk_page_tree(fz_context *ctx, fz_document *doc) +{ + pdf_document *pdf = pdf_specifics(ctx, doc); + if (pdf != NULL) + pdf_set_page_tree_cache(ctx, pdf, 0); +} + pardes_pdf_document * pardes_pdf_open_memory(const unsigned char *bytes, size_t length, int *page_count) { @@ -398,6 +412,7 @@ pardes_pdf_open_memory(const unsigned char *bytes, size_t length, int *page_coun buffer = fz_new_buffer_from_copied_data(ctx, bytes, length); stream = fz_open_buffer(ctx, buffer); doc = fz_open_document_with_stream(ctx, "application/pdf", stream); + pardes_pdf_walk_page_tree(ctx, doc); pages = fz_count_pages(ctx, doc); if (pages < 1) fz_throw(ctx, FZ_ERROR_FORMAT, "PDF has no pages"); @@ -490,6 +505,7 @@ pardes_pdf_lane_open(pardes_pdf_document *lane) { stream = fz_open_buffer(ctx, lane->base->buffer); doc = fz_open_document_with_stream(ctx, "application/pdf", stream); + pardes_pdf_walk_page_tree(ctx, doc); if (fz_count_pages(ctx, doc) != lane->page_count) fz_throw(ctx, FZ_ERROR_FORMAT, "PDF lane counts other pages"); } |
