< 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,178 ****
* This is used by jdk.internal.module.SystemModules class
* generated at link time.
*/
public static class Builder {
final String algorithm;
! Map<String, byte[]> nameToHash;
! Builder(String algorithm) {
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) {
return new ModuleHashes(algorithm, nameToHash);
} else {
return null;
}
}
--- 147,176 ----
* This is used by jdk.internal.module.SystemModules class
* generated at link time.
*/
public static class Builder {
final String algorithm;
! final Map<String, byte[]> nameToHash;
! 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) {
nameToHash.put(mn, hash);
return this;
}
/**
* Builds a {@code ModuleHashes}.
*/
public ModuleHashes build() {
! if (!nameToHash.isEmpty()) {
return new ModuleHashes(algorithm, nameToHash);
} else {
return null;
}
}
< prev index next >