diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2017-02-23 15:11:08 +0100 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2017-03-01 15:22:46 +0100 |
commit | 53f816f2f06de5aeb13cac72232c4f52714201cb (patch) | |
tree | 924eccc6f31db7564ab434a3491b27c7d572eed3 /source/pdf/pdf-outline.c | |
parent | 8c547d302fb23950bc3f928a37d4c8baf93838cc (diff) | |
download | mupdf-53f816f2f06de5aeb13cac72232c4f52714201cb.tar.xz |
Add page lookup cache for faster link destination lookups in outlines.
Loading outlines wants to look up all link destinations, and doing the
normal link destination lookups triggers loading all page objects used.
This means we need to parse a lot of objects, which can be quite slow.
We can load the page tree faster by only looking at intermediate page
tree nodes. If we load the page tree and create a reverse lookup
table for use when loading the outline, we can speed up the time to
run 'mutool show pdfref17.pdf outline' from 900ms to 100ms.
Diffstat (limited to 'source/pdf/pdf-outline.c')
-rw-r--r-- | source/pdf/pdf-outline.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/source/pdf/pdf-outline.c b/source/pdf/pdf-outline.c index c31a1954..7c8cfdaa 100644 --- a/source/pdf/pdf-outline.c +++ b/source/pdf/pdf-outline.c @@ -69,12 +69,21 @@ fz_outline * pdf_load_outline(fz_context *ctx, pdf_document *doc) { pdf_obj *root, *obj, *first; + fz_outline *outline = NULL; - root = pdf_dict_get(ctx, pdf_trailer(ctx, doc), PDF_NAME_Root); - obj = pdf_dict_get(ctx, root, PDF_NAME_Outlines); - first = pdf_dict_get(ctx, obj, PDF_NAME_First); - if (first) - return pdf_load_outline_imp(ctx, doc, first); + pdf_load_page_tree(ctx, doc); /* cache page tree for fast link destination lookups */ + fz_try(ctx) + { + root = pdf_dict_get(ctx, pdf_trailer(ctx, doc), PDF_NAME_Root); + obj = pdf_dict_get(ctx, root, PDF_NAME_Outlines); + first = pdf_dict_get(ctx, obj, PDF_NAME_First); + if (first) + outline = pdf_load_outline_imp(ctx, doc, first); + } + fz_always(ctx) + pdf_drop_page_tree(ctx, doc); + fz_catch(ctx) + fz_rethrow(ctx); - return NULL; + return outline; } |