From 13c259ab2e4bfc1da6fc4809c58b1218a7e0b270 Mon Sep 17 00:00:00 2001 From: John Whitington Date: Mon, 29 May 2017 14:02:34 +0100 Subject: [PATCH] fastrefnums --- cpdf.ml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cpdf.ml b/cpdf.ml index dbcd787..e526c08 100644 --- a/cpdf.ml +++ b/cpdf.ml @@ -1199,12 +1199,16 @@ let list_bookmarks encoding range pdf output = in let bookmarks = Pdfmarks.read_bookmarks pdf in let refnums = Pdf.page_reference_numbers pdf in + let rangetable = hashset_of_list range in + let fastrefnums = hashtable_of_dictionary (combine refnums (indx refnums)) in + (* Find the pagenumber of each bookmark target. If it is in the range, + * keep that bookmark. Also keep the bookmark if its target is the null + * destination. *) let inrange = - (* n ^ 2 here too? *) keep (function x -> x.Pdfmarks.target = Pdfdest.NullDestination || - mem (Pdfpage.pagenumber_of_target ~refnums pdf x.Pdfmarks.target) range) bookmarks + Hashtbl.mem rangetable (Pdfpage.pagenumber_of_target ~fastrefnums pdf x.Pdfmarks.target)) bookmarks in iter (function mark ->