< prev index next >
src/java.base/share/classes/jdk/internal/module/ModuleHashes.java
Print this page
rev 16336 : 8171373: Reduce copying during initialization of ModuleHashes
Reviewed-by: alanb, mchung, chegar
@@ -147,32 +147,30 @@
* This is used by jdk.internal.module.SystemModules class
* generated at link time.
*/
public static class Builder {
final String algorithm;
- Map<String, byte[]> nameToHash;
+ final Map<String, byte[]> nameToHash;
- Builder(String algorithm) {
+ Builder(String algorithm, int initialCapacity) {
+ this.nameToHash = new HashMap<>(initialCapacity);
this.algorithm = Objects.requireNonNull(algorithm);
}
/**
* Sets the module hash for the given module name
*/
public Builder hashForModule(String mn, byte[] hash) {
- if (nameToHash == null)
- nameToHash = new HashMap<>();
-
nameToHash.put(mn, hash);
return this;
}
/**
* Builds a {@code ModuleHashes}.
*/
public ModuleHashes build() {
- if (nameToHash != null) {
+ if (!nameToHash.isEmpty()) {
return new ModuleHashes(algorithm, nameToHash);
} else {
return null;
}
}
< prev index next >