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

Reply via email to