You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Alan Thomas <ja...@verizon.net> on 2009/07/06 02:10:24 UTC
PDDocumentCatalog etc. Optimization ?
I was iterating over some pages in a PDDocument, and did it this
way:
List pages = document.getDocumentCatalog().getAllPages();
for (Object obj : pages)
{
PDPage page = (PDPage)obj;
because the list returned by PDDocumentCatalog.getAllPages() is declared as
an
ArrayList vice an ArrayList of PDPages (see below). Thus, the extra type
conversion
in every iteration.
public List getAllPages()
{
List retval = new ArrayList();
PDPageNode rootNode = getPages();
//old (slower):
//getPageObjects( rootNode, retval );
rootNode.getAllKids(retval);
return retval;
}
The Java 6 "for" loop is typically 25+% faster for iterating over a
list than using a list iterator.
However, in this case, it made no difference (over 10-20 iterations and only
looking at seconds).
Would it be possible to do this sort of optimizations esp. on methods
that return a list of pages?
I realize there may be many complications of which I am not aware.
Thanks, Alan