Author: lehmi Date: Wed Jun 12 05:56:10 2024 New Revision: 1918274 URL: http://svn.apache.org/viewvc?rev=1918274&view=rev Log: PDFBOX-5809: use HashSet instead of ArraysList to speed up the import of pages
Modified: pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSArray.java pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java Modified: pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSArray.java URL: http://svn.apache.org/viewvc/pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSArray.java?rev=1918274&r1=1918273&r2=1918274&view=diff ============================================================================== --- pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSArray.java (original) +++ pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSArray.java Wed Jun 12 05:56:10 2024 @@ -746,9 +746,24 @@ public class COSArray extends COSBase im * * @param indirectObjects a list of already found indirect objects. * + * @deprecated, use {@link #getIndirectObjectKeys(Collection)} instead */ public void getIndirectObjectKeys(List<COSObjectKey> indirectObjects) { + getIndirectObjectKeys((Collection<COSObjectKey>) indirectObjects); + } + + /** + * Collects all indirect objects numbers within this COSArray and all included dictionaries. It is used to avoid + * mixed up object numbers when importing an existing page to another pdf. + * + * Expert use only. You might run into an endless recursion if choosing a wrong starting point. + * + * @param indirectObjects a collection of already found indirect objects. + * + */ + public void getIndirectObjectKeys(Collection<COSObjectKey> indirectObjects) + { if (indirectObjects == null) { return; Modified: pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java URL: http://svn.apache.org/viewvc/pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java?rev=1918274&r1=1918273&r2=1918274&view=diff ============================================================================== --- pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java (original) +++ pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java Wed Jun 12 05:56:10 2024 @@ -1422,9 +1422,24 @@ public class COSDictionary extends COSBa * * @param indirectObjects a list of already found indirect objects. * + * @deprecated, use {@link #getIndirectObjectKeys(Collection)} instead */ public void getIndirectObjectKeys(List<COSObjectKey> indirectObjects) { + getIndirectObjectKeys((Collection<COSObjectKey>) indirectObjects); + } + + /** + * Collects all indirect objects numbers within this dictionary and all included dictionaries. It is used to avoid + * mixed up object numbers when importing an existing page to another pdf. + * + * Expert use only. You might run into an endless recursion if choosing a wrong starting point. + * + * @param indirectObjects a collection of already found indirect objects. + * + */ + public void getIndirectObjectKeys(Collection<COSObjectKey> indirectObjects) + { if (indirectObjects == null) { return; Modified: pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java URL: http://svn.apache.org/viewvc/pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java?rev=1918274&r1=1918273&r2=1918274&view=diff ============================================================================== --- pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java (original) +++ pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java Wed Jun 12 05:56:10 2024 @@ -28,6 +28,7 @@ import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -152,7 +153,7 @@ public class PDDocument implements Close private boolean signatureAdded = false; // cache for the key of all imported indirect objects - private final List<COSObjectKey> indirectObjectKeys = new ArrayList<>(); + private final Collection<COSObjectKey> indirectObjectKeys = new HashSet<>(); /** * Creates an empty PDF document.