@@ -1081,13 +1081,15 @@ private String getManifestName(boolean onlyIfSignatureRelatedFiles) {
1081
1081
* optimization when looking up potentially versioned entries.
1082
1082
* Returns an empty array if no versioned entries exist.
1083
1083
*/
1084
- private int [] getMetaInfVersions (String name ) {
1084
+ private BitSet getMetaInfVersions (String name ) {
1085
1085
synchronized (this ) {
1086
1086
ensureOpen ();
1087
- return res .zsrc .metaVersions .getOrDefault (name , Source . EMPTY_META_VERSIONS );
1087
+ return res .zsrc .metaVersions .getOrDefault (name , EMPTY_VERSIONS );
1088
1088
}
1089
1089
}
1090
1090
1091
+ private static final BitSet EMPTY_VERSIONS = new BitSet ();
1092
+
1091
1093
/**
1092
1094
* Returns the value of the System property which indicates whether the
1093
1095
* Extra ZIP64 validation should be disabled.
@@ -1124,7 +1126,7 @@ public String getManifestName(JarFile jar, boolean onlyIfHasSignatureRelatedFile
1124
1126
return ((ZipFile )jar ).getManifestName (onlyIfHasSignatureRelatedFiles );
1125
1127
}
1126
1128
@ Override
1127
- public int [] getMetaInfVersions (JarFile jar , String name ) {
1129
+ public BitSet getMetaInfVersions (JarFile jar , String name ) {
1128
1130
return ((ZipFile )jar ).getMetaInfVersions (name );
1129
1131
}
1130
1132
@ Override
@@ -1162,7 +1164,6 @@ private static class Source {
1162
1164
private static final int META_INF_LEN = 9 ;
1163
1165
// "META-INF/versions//".length()
1164
1166
private static final int META_INF_VERSIONS_LEN = 19 ;
1165
- private static final int [] EMPTY_META_VERSIONS = new int [0 ];
1166
1167
// CEN size is limited to the maximum array size in the JDK
1167
1168
private static final int MAX_CEN_SIZE = ArraysSupport .SOFT_MAX_ARRAY_LENGTH ;
1168
1169
@@ -1179,7 +1180,7 @@ private static class Source {
1179
1180
private int manifestPos = -1 ; // position of the META-INF/MANIFEST.MF, if exists
1180
1181
private int manifestNum = 0 ; // number of META-INF/MANIFEST.MF, case insensitive
1181
1182
private int [] signatureMetaNames ; // positions of signature related entries, if such exist
1182
- private Map <String , int [] > metaVersions ; // Set of versions found in META-INF/versions/, by entry name
1183
+ private Map <String , BitSet > metaVersions ; // Set of versions found in META-INF/versions/, by entry name
1183
1184
private final boolean startsWithLoc ; // true, if ZIP file starts with LOCSIG (usually true)
1184
1185
1185
1186
// A Hashmap for all entries.
@@ -1745,7 +1746,7 @@ private void initCEN(int knownTotal) throws IOException {
1745
1746
ArrayList <Integer > signatureNames = null ;
1746
1747
// Map entry name to the set of versions seen in
1747
1748
// META-INF/versions/{version}/{name}
1748
- Map <String , Set < Integer > > metaVersionsMap = null ;
1749
+ Map <String , BitSet > metaVersionsMap = null ;
1749
1750
1750
1751
// Iterate through the entries in the central directory
1751
1752
int idx = 0 ; // Index into the entries array
@@ -1790,7 +1791,7 @@ private void initCEN(int knownTotal) throws IOException {
1790
1791
// Add version for name
1791
1792
if (metaVersionsMap == null )
1792
1793
metaVersionsMap = new HashMap <>();
1793
- metaVersionsMap .computeIfAbsent (name , n -> new HashSet <> ()).add (version );
1794
+ metaVersionsMap .computeIfAbsent (name , _ -> new BitSet ()).set (version );
1794
1795
}
1795
1796
}
1796
1797
}
@@ -1809,18 +1810,7 @@ private void initCEN(int knownTotal) throws IOException {
1809
1810
}
1810
1811
}
1811
1812
if (metaVersionsMap != null ) {
1812
- metaVersions = new HashMap <>();
1813
- for (var entry : metaVersionsMap .entrySet ()) {
1814
- // Convert Set<Integer> to int[] for performance
1815
- int [] versions = new int [entry .getValue ().size ()];
1816
- int c = 0 ;
1817
- for (Integer i : entry .getValue ()) {
1818
- versions [c ++] = i .intValue ();
1819
- }
1820
- // JarFile::getVersionedEntry expects sorted versions
1821
- Arrays .sort (versions );
1822
- metaVersions .put (entry .getKey (), versions );
1823
- }
1813
+ metaVersions = metaVersionsMap ;
1824
1814
} else {
1825
1815
metaVersions = Map .of ();
1826
1816
}
0 commit comments