From 4a99615a609eec2b84bb2341d74fac46a5998137 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Mon, 25 Jun 2018 13:15:50 +0200 Subject: Pass rect and matrix by value in geometry functions. Several things irk me about passing values as const pointers: * They can be NULL, which is not a valid value. * They require explicit temporary variables for storage. * They don't compose easily in a legible manner, requiring weird pointer passing semantics where the variable being assigned is hidden as an argument in the innermost function call. * We can't change the value through the pointer, requiring yet more local variables to hold copies of the input value. In the device interface where we pass a matrix to a function, we often find ourselves making a local copy of the matrix so we can concatenate other transforms to it. This copying is a lot of unnecessary busywork that I hope to eventually avoid by laying the groundwork with this commit. This is a rather large API change, so I apologize for the inconvenience, but I hope the end result and gain in legibility will be worth the pain. --- source/fitz/document.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'source/fitz/document.c') diff --git a/source/fitz/document.c b/source/fitz/document.c index b74f7de5..3dc41a75 100644 --- a/source/fitz/document.c +++ b/source/fitz/document.c @@ -328,25 +328,23 @@ fz_load_page(fz_context *ctx, fz_document *doc, int number) fz_link * fz_load_links(fz_context *ctx, fz_page *page) { - if (page && page->load_links && page) + if (page && page->load_links) return page->load_links(ctx, page); return NULL; } -fz_rect * -fz_bound_page(fz_context *ctx, fz_page *page, fz_rect *r) +fz_rect +fz_bound_page(fz_context *ctx, fz_page *page) { - if (page && page->bound_page && page && r) - return page->bound_page(ctx, page, r); - if (r) - *r = fz_empty_rect; - return r; + if (page && page->bound_page) + return page->bound_page(ctx, page); + return fz_empty_rect; } fz_annot * fz_first_annot(fz_context *ctx, fz_page *page) { - if (page && page->first_annot && page) + if (page && page->first_annot) return page->first_annot(ctx, page); return NULL; } @@ -359,14 +357,12 @@ fz_next_annot(fz_context *ctx, fz_annot *annot) return NULL; } -fz_rect * -fz_bound_annot(fz_context *ctx, fz_annot *annot, fz_rect *rect) +fz_rect +fz_bound_annot(fz_context *ctx, fz_annot *annot) { - if (annot && annot->bound_annot && rect) - return annot->bound_annot(ctx, annot, rect); - if (rect) - *rect = fz_empty_rect; - return rect; + if (annot && annot->bound_annot) + return annot->bound_annot(ctx, annot); + return fz_empty_rect; } void -- cgit v1.2.3