diff options
author | Paul Gardiner <paul.gardiner@artifex.com> | 2013-11-08 12:28:09 +0000 |
---|---|---|
committer | Paul Gardiner <paul.gardiner@artifex.com> | 2013-11-08 14:28:16 +0000 |
commit | 03a56be6b569c034fddcc095ba5dd137fa404c9f (patch) | |
tree | 34a96c536462b58e47df9a2c2bb23c5868089ec7 /source/pdf | |
parent | c0c9d9800e3c015a1f401df465fb907eb23fa18c (diff) | |
download | mupdf-03a56be6b569c034fddcc095ba5dd137fa404c9f.tar.xz |
Use an end pointer for the annotation list to avoid unnecessary iteration
Diffstat (limited to 'source/pdf')
-rw-r--r-- | source/pdf/pdf-annot.c | 18 | ||||
-rw-r--r-- | source/pdf/pdf-page.c | 3 |
2 files changed, 12 insertions, 9 deletions
diff --git a/source/pdf/pdf-annot.c b/source/pdf/pdf-annot.c index edab4cd5..c0436885 100644 --- a/source/pdf/pdf-annot.c +++ b/source/pdf/pdf-annot.c @@ -491,8 +491,8 @@ static const char *annot_type_str(fz_annot_type type) } } -pdf_annot * -pdf_load_annots(pdf_document *doc, pdf_obj *annots, pdf_page *page) +void +pdf_load_annots(pdf_document *doc, pdf_page *page, pdf_obj *annots) { pdf_annot *annot, *head, **itr; pdf_obj *obj, *ap, *as, *n, *rect; @@ -505,6 +505,7 @@ pdf_load_annots(pdf_document *doc, pdf_obj *annots, pdf_page *page) fz_var(keep_annot); head = NULL; + itr = &head; len = pdf_array_len(annots); /* @@ -515,7 +516,6 @@ pdf_load_annots(pdf_document *doc, pdf_obj *annots, pdf_page *page) */ fz_try(ctx) { - itr = &head; for (i = 0; i < len; i++) { obj = pdf_array_get(annots, i); @@ -617,7 +617,8 @@ pdf_load_annots(pdf_document *doc, pdf_obj *annots, pdf_page *page) } } - return head; + page->annots = head; + page->annot_tailp = itr; } void @@ -710,7 +711,6 @@ pdf_create_annot(pdf_document *doc, pdf_page *page, fz_annot_type type) { fz_context *ctx = doc->ctx; pdf_annot *annot = NULL; - pdf_annot **lastptr; pdf_obj *annot_obj = pdf_new_dict(doc, 0); pdf_obj *ind_obj = NULL; @@ -757,9 +757,8 @@ pdf_create_annot(pdf_document *doc, pdf_page *page, fz_annot_type type) pdf_free_annot below actually frees a list. Put the new annot at the end of the list, so that it will be drawn last. */ - for (lastptr = &page->annots; *lastptr; lastptr = &(*lastptr)->next) - ; - *lastptr = annot; + *page->annot_tailp = annot; + page->annot_tailp = &annot->next; doc->dirty = 1; } @@ -800,6 +799,9 @@ pdf_delete_annot(pdf_document *doc, pdf_page *page, pdf_annot *annot) return; *annotptr = annot->next; + /* If the removed annotation was the last in the list adjust the end pointer */ + if (*annotptr == NULL) + page->annot_tailp = annotptr; /* Stick it in the deleted list */ annot->next = page->deleted_annots; diff --git a/source/pdf/pdf-page.c b/source/pdf/pdf-page.c index 29366d62..602564ce 100644 --- a/source/pdf/pdf-page.c +++ b/source/pdf/pdf-page.c @@ -365,6 +365,7 @@ pdf_load_page(pdf_document *doc, int number) page->transparency = 0; page->links = NULL; page->annots = NULL; + page->annot_tailp = &page->annots; page->deleted_annots = NULL; page->tmp_annots = NULL; page->me = pdf_keep_obj(pageobj); @@ -423,7 +424,7 @@ pdf_load_page(pdf_document *doc, int number) if (obj) { page->links = pdf_load_link_annots(doc, obj, &page->ctm); - page->annots = pdf_load_annots(doc, obj, page); + pdf_load_annots(doc, page, obj); } } fz_catch(ctx) |