OpenJDK / jigsaw / jake / jdk
changeset 14219:a0cd5da340dc
Use Collections.emptySet/-Map in ModuleDescriptor where appropriate to save footprint
author | redestad |
---|---|
date | Thu, 15 Oct 2015 08:13:17 +0100 |
parents | 515149589edb |
children | 7211ac32411a |
files | src/java.base/share/classes/java/lang/module/ModuleDescriptor.java |
diffstat | 1 files changed, 23 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/java.base/share/classes/java/lang/module/ModuleDescriptor.java Tue Oct 13 08:08:27 2015 +0100 +++ b/src/java.base/share/classes/java/lang/module/ModuleDescriptor.java Thu Oct 15 08:13:17 2015 +0100 @@ -534,16 +534,16 @@ assert (rqs.stream().map(Requires::name).sorted().distinct().count() == rqs.size()) : "Module " + name + " has duplicate requires"; - this.requires = Collections.unmodifiableSet(rqs); + this.requires = emptyOrUnmodifiableSet(rqs); Set<Exports> exs = new HashSet<>(exports.values()); assert (exs.stream().map(Exports::source).sorted().distinct().count() == exs.size()) : "Module " + name + " has duplicate exports"; - this.exports = Collections.unmodifiableSet(exs); + this.exports = emptyOrUnmodifiableSet(exs); - this.uses = Collections.unmodifiableSet(uses); - this.provides = Collections.unmodifiableMap(provides); + this.uses = emptyOrUnmodifiableSet(uses); + this.provides = emptyOrUnmodifiableMap(provides); this.version = Optional.ofNullable(version); this.mainClass = Optional.ofNullable(mainClass); @@ -551,10 +551,10 @@ assert !exports.keySet().stream().anyMatch(conceals::contains) : "Module " + name + ": Package sets overlap"; - this.conceals = Collections.unmodifiableSet(conceals); + this.conceals = emptyOrUnmodifiableSet(conceals); Set<String> pkgs = new HashSet<>(conceals); pkgs.addAll(exports.keySet()); - this.packages = Collections.unmodifiableSet(pkgs); + this.packages = emptyOrUnmodifiableSet(pkgs); } @@ -578,8 +578,8 @@ Set<String> conceals = new HashSet<>(pkgs); exports.stream().map(Exports::source).forEach(conceals::remove); - this.conceals = Collections.unmodifiableSet(conceals); - this.packages = Collections.unmodifiableSet(pkgs); + this.conceals = emptyOrUnmodifiableSet(conceals); + this.packages = emptyOrUnmodifiableSet(pkgs); } @@ -1133,6 +1133,21 @@ return ModuleInfo.read(bb, null); } + private static <K,V> Map<K,V> emptyOrUnmodifiableMap(Map<K,V> map) { + if (map.isEmpty()) { + return Collections.emptyMap(); + } else { + return Collections.unmodifiableMap(map); + } + } + + private static <T> Set<T> emptyOrUnmodifiableSet(Set<T> set) { + if (set.isEmpty()) { + return Collections.emptySet(); + } else { + return Collections.unmodifiableSet(set); + } + } static { /**