You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2024/06/11 17:22:35 UTC
svn commit: r1918261 - in /pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox: cos/COSDictionary.java util/SmallMap.java
Author: lehmi
Date: Tue Jun 11 17:22:34 2024
New Revision: 1918261
URL: http://svn.apache.org/viewvc?rev=1918261&view=rev
Log:
PDFBOX-5824: remove SmallMap optimisation based on a proposal from Jonathan Prates
Modified:
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/util/SmallMap.java
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=1918261&r1=1918260&r2=1918261&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 Tue Jun 11 17:22:34 2024
@@ -35,7 +35,6 @@ import org.apache.commons.logging.LogFac
import org.apache.pdfbox.io.IOUtils;
import org.apache.pdfbox.pdmodel.common.COSObjectable;
import org.apache.pdfbox.util.DateConverter;
-import org.apache.pdfbox.util.SmallMap;
/**
* This class represents a dictionary where name/value pairs reside.
@@ -52,12 +51,11 @@ public class COSDictionary extends COSBa
private static final Log LOG = LogFactory.getLog(COSDictionary.class);
private static final String PATH_SEPARATOR = "/";
- private static final int MAP_THRESHOLD = 1000;
/**
* The name-value pairs of this dictionary. The pairs are kept in the order they were added to the dictionary.
*/
- protected Map<COSName, COSBase> items = new SmallMap<>();
+ protected Map<COSName, COSBase> items = new LinkedHashMap<>();
private final COSUpdateState updateState;
/**
@@ -206,10 +204,6 @@ public class COSDictionary extends COSBa
}
else
{
- if (items instanceof SmallMap && items.size() >= MAP_THRESHOLD)
- {
- items = new LinkedHashMap<>(items);
- }
items.put(key, value);
getUpdateState().update(value);
}
@@ -1273,10 +1267,6 @@ public class COSDictionary extends COSBa
*/
public void addAll(COSDictionary dict)
{
- if (items instanceof SmallMap && items.size() + dict.items.size() >= MAP_THRESHOLD)
- {
- items = new LinkedHashMap<>(items);
- }
items.putAll(dict.items);
}
Modified: pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/util/SmallMap.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/util/SmallMap.java?rev=1918261&r1=1918260&r2=1918261&view=diff
==============================================================================
--- pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/util/SmallMap.java (original)
+++ pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/util/SmallMap.java Tue Jun 11 17:22:34 2024
@@ -25,14 +25,17 @@ import java.util.Map;
import java.util.Set;
/**
- * Map implementation with a smallest possible memory usage.
- * It should only be used for maps with small number of items
- * (e.g. <30) since most operations have an O(n) complexity.
- * Thus it should be used in cases with large number of map
+ * Map implementation with a smallest possible memory usage. It should only be used for maps with small number of items
+ * (e.g. <30) since most operations have an O(n) complexity. Thus it should be used in cases with large number of map
* objects, each having only few items.
*
- * <p><code>null</code> is not supported for keys or values.</p>
+ * <p>
+ * <code>null</code> is not supported for keys or values.
+ * </p>
+ *
+ * @deprecated will be removed in 4.0.0
*/
+@Deprecated
public class SmallMap<K, V> implements Map<K, V>
{
/**
@@ -285,7 +288,7 @@ public class SmallMap<K, V> implements M
return Collections.emptySet();
}
- Set<K> keys = new LinkedHashSet<>();
+ Set<K> keys = new LinkedHashSet<>(mapArr.length >> 1);
for (int kIdx = 0; kIdx < mapArr.length; kIdx+=2)
{
keys.add((K)mapArr[kIdx]);
@@ -381,7 +384,7 @@ public class SmallMap<K, V> implements M
return Collections.emptySet();
}
- Set<java.util.Map.Entry<K, V>> entries = new LinkedHashSet<>();
+ Set<java.util.Map.Entry<K, V>> entries = new LinkedHashSet<>(mapArr.length >> 1);
for (int kIdx = 0; kIdx < mapArr.length; kIdx+=2)
{
entries.add(new SmallMapEntry(kIdx));