You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2023/03/08 13:29:19 UTC

svn commit: r1908206 - /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoice.java

Author: tilman
Date: Wed Mar  8 13:29:19 2023
New Revision: 1908206

URL: http://svn.apache.org/viewvc?rev=1908206&view=rev
Log:
PDFBOX-4892: optimize, as suggested by valerybokov

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoice.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoice.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoice.java?rev=1908206&r1=1908205&r2=1908206&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoice.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoice.java Wed Mar  8 13:29:19 2023
@@ -412,12 +412,13 @@ public abstract class PDChoice extends P
             {
                 throw new IllegalArgumentException("The list box does not allow multiple selections.");
             }
-            if (!getOptions().containsAll(values))
+            List<String> options = getOptions();
+            if (!options.containsAll(values))
             {
                 throw new IllegalArgumentException("The values are not contained in the selectable options.");
             }
             getCOSObject().setItem(COSName.V, COSArrayList.convertStringListToCOSStringCOSArray(values));
-            updateSelectedOptionsIndex(values);
+            updateSelectedOptionsIndex(values, options);
         }
         else
         {
@@ -477,10 +478,9 @@ public abstract class PDChoice extends P
     /**
      * Update the 'I' key based on values set.
      */
-    private void updateSelectedOptionsIndex(List<String> values)
+    private void updateSelectedOptionsIndex(List<String> values, List<String> options)
     {
-        List<String> options = getOptions();
-        List<Integer> indices = new ArrayList<Integer>();
+        List<Integer> indices = new ArrayList<Integer>(values.size());
 
         for (String value : values)
         {