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 2020/12/29 12:14:19 UTC
svn commit: r1884902 -
/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/encoding/Encoding.java
Author: tilman
Date: Tue Dec 29 12:14:19 2020
New Revision: 1884902
URL: http://svn.apache.org/viewvc?rev=1884902&view=rev
Log:
PDFBOX-5056: remove double-checked locking, as suggested by Mike Kaplinskiy
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/encoding/Encoding.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/encoding/Encoding.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/encoding/Encoding.java?rev=1884902&r1=1884901&r2=1884902&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/encoding/Encoding.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/encoding/Encoding.java Tue Dec 29 12:14:19 2020
@@ -18,9 +18,8 @@ package org.apache.pdfbox.pdmodel.font.e
import java.util.Collections;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Map;
-import java.util.Set;
+
import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.pdmodel.common.COSObjectable;
@@ -61,9 +60,15 @@ public abstract class Encoding implement
}
}
+ /**
+ * code-to-name map. Derived classes should not modify the map after class construction.
+ */
protected final Map<Integer, String> codeToName = new HashMap<>(250);
+
+ /**
+ * name-to-code map. Derived classes should not modify the map after class construction.
+ */
protected final Map<String, Integer> inverted = new HashMap<>(250);
- private volatile Set<String> names;
/**
* Returns an unmodifiable view of the code -> name mapping.
@@ -87,7 +92,8 @@ public abstract class Encoding implement
}
/**
- * This will add a character encoding. An already existing mapping is preservered when creating the reverse mapping.
+ * This will add a character encoding. An already existing mapping is preseved when creating
+ * the reverse mapping. Should only be used during construction of the class.
*
* @see #overwrite(int, String)
*
@@ -101,8 +107,9 @@ public abstract class Encoding implement
}
/**
- * This will add a character encoding. An already existing mapping is overwritten when creating the reverse mapping.
- *
+ * This will add a character encoding. An already existing mapping is overwritten when creating
+ * the reverse mapping. Should only be used during construction of the class.
+ *
* @see Encoding#add(int, String)
*
* @param code character code
@@ -131,23 +138,7 @@ public abstract class Encoding implement
*/
public boolean contains(String name)
{
- // we have to wait until all add() calls are done before building the name cache
- // otherwise /Differences won't be accounted for
- if (names == null)
- {
- synchronized(this)
- {
- if (names == null)
- {
- // PDFBOX-3404: avoid possibility that one thread ends up with newly created empty map from other thread
- Set<String> tmpSet = new HashSet<>(codeToName.values());
- // make sure that assignment is done after initialisation is complete
- names = tmpSet;
- }
- }
- // at this point, names will never be null.
- }
- return names.contains(name);
+ return inverted.containsKey(name);
}
/**