when we have lots of pages, we trigger a O(n^2) loop.
Do two things to reduce this
(a) be smarter about recalculating page numbers, so we only recalculate
the set of page numbers that need recalculating
(b) duplicate the last page repeatedly, instead of the first page, so we
don't recalculate all the page numbers for each page we duplicate
Change-Id: I40aca812b47a9551039c5855b1c8d26f5f171f41
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172942
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Jenkins