Skip to content

Commit

Permalink
8273710: Remove redundant stream() call before forEach in jdk.jdeps
Browse files Browse the repository at this point in the history
Reviewed-by: dfuchs, shade
  • Loading branch information
turbanoff authored and shipilev committed Sep 16, 2021
1 parent 59b2478 commit 7e92abe
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ public int hashCode() {
public Graph<Node> moduleGraph() {
Graph.Builder<Node> builder = new Graph.Builder<>();

archives().stream()
archives()
.forEach(m -> {
Node u = new Node(m.getName(), Info.REQUIRES);
builder.addNode(u);
Expand Down
15 changes: 6 additions & 9 deletions src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Graph.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ public Set<Edge<T>> edgesFrom(T u) {
*/
public Graph<T> reduce() {
Builder<T> builder = new Builder<>();
nodes.stream()
.forEach(u -> {
nodes.forEach(u -> {
builder.addNode(u);
edges.get(u).stream()
.filter(v -> !pathExists(u, v, false))
Expand All @@ -97,8 +96,7 @@ public Graph<T> reduce(Graph<T> g) {
}

Builder<T> builder = new Builder<>();
nodes.stream()
.forEach(u -> {
nodes.forEach(u -> {
builder.addNode(u);
// filter the edge if there exists a path from u to v in the given g
// or there exists another path from u to v in this graph
Expand All @@ -108,7 +106,7 @@ public Graph<T> reduce(Graph<T> g) {
});

// add the overlapped edges from this graph and the given g
g.edges().keySet().stream()
g.edges().keySet()
.forEach(u -> g.adjacentNodes(u).stream()
.filter(v -> isAdjacent(u, v))
.forEach(v -> builder.addEdge(u, v)));
Expand Down Expand Up @@ -147,7 +145,7 @@ public Graph<T> transpose() {
builder.addNodes(nodes);
// reverse edges
edges.keySet().forEach(u -> {
edges.get(u).stream()
edges.get(u)
.forEach(v -> builder.addEdge(v, u));
});
return builder.build();
Expand Down Expand Up @@ -214,8 +212,7 @@ private boolean pathExists(T u, T v, boolean includeAdjacent) {

public void printGraph(PrintWriter out) {
out.println("graph for " + nodes);
nodes.stream()
.forEach(u -> adjacentNodes(u).stream()
nodes.forEach(u -> adjacentNodes(u)
.forEach(v -> out.format(" %s -> %s%n", u, v)));
}

Expand Down Expand Up @@ -322,7 +319,7 @@ private void visit(T node, Set<T> visited, Set<T> done) {
return;
}
visited.add(node);
graph.edges().get(node).stream()
graph.edges().get(node)
.forEach(x -> visit(x, visited, done));
done.add(node);
result.addLast(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public Set<Deque<Archive>> inverseDependences() throws IOException {
targets().forEach(builder::addNode);

// transpose the module graph
configuration.getModules().values().stream()
configuration.getModules().values()
.forEach(m -> {
builder.addNode(m);
m.descriptor().requires().stream()
Expand All @@ -152,7 +152,7 @@ public Set<Deque<Archive>> inverseDependences() throws IOException {

// add the dependences from the analysis
Map<Archive, Set<Archive>> dependences = dependencyFinder.dependences();
dependences.entrySet().stream()
dependences.entrySet()
.forEach(e -> {
Archive u = e.getKey();
builder.addNode(u);
Expand Down Expand Up @@ -215,7 +215,7 @@ private Set<Deque<Archive>> findPaths(Graph<Archive> graph, Archive target) {
}

// push unvisited adjacent edges
unvisitedDeps.stream().forEach(deque::push);
unvisitedDeps.forEach(deque::push);


// when the adjacent edges of a node are visited, pop it from the path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,8 @@ private ModuleDescriptor dropHashes(ModuleDescriptor md) {
md.requires().forEach(builder::requires);
md.exports().forEach(builder::exports);
md.opens().forEach(builder::opens);
md.provides().stream().forEach(builder::provides);
md.uses().stream().forEach(builder::uses);
md.provides().forEach(builder::provides);
md.uses().forEach(builder::uses);
builder.packages(md.packages());
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ boolean run(JdepsConfiguration config, JdepsWriter writer, Type type)
if (!options.nowarning) {
analyzer.archives()
.forEach(archive -> archive.reader()
.skippedEntries().stream()
.skippedEntries()
.forEach(name -> warning("warn.skipped.entry", name)));
}

Expand All @@ -796,7 +796,7 @@ boolean run(JdepsConfiguration config, JdepsWriter writer, Type type)
log.format("%-40s %s%n",
internalApiTitle.replaceAll(".", "-"),
replacementApiTitle.replaceAll(".", "-"));
jdkInternals.entrySet().stream()
jdkInternals.entrySet()
.forEach(e -> {
String key = e.getKey();
String[] lines = e.getValue().split("\\n");
Expand Down Expand Up @@ -1111,7 +1111,7 @@ private JdepsFilter dependencyFilter(JdepsConfiguration config) {

// --require
if (!options.requires.isEmpty()) {
options.requires.stream()
options.requires
.forEach(mn -> {
Module m = config.findModule(mn).get();
builder.requires(mn, m.packages());
Expand Down
4 changes: 2 additions & 2 deletions src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,10 @@ public Module build() {
descriptor.packages().forEach(pn -> exports.put(pn, Collections.emptySet()));
descriptor.packages().forEach(pn -> opens.put(pn, Collections.emptySet()));
} else {
descriptor.exports().stream()
descriptor.exports()
.forEach(exp -> exports.computeIfAbsent(exp.source(), _k -> new HashSet<>())
.addAll(exp.targets()));
descriptor.opens().stream()
descriptor.opens()
.forEach(exp -> opens.computeIfAbsent(exp.source(), _k -> new HashSet<>())
.addAll(exp.targets()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,14 @@ private ModuleDescriptor descriptor(Set<Module> requiresTransitive,
private Graph<Module> buildReducedGraph() {
ModuleGraphBuilder rpBuilder = new ModuleGraphBuilder(configuration);
rpBuilder.addModule(root);
requiresTransitive.stream()
.forEach(m -> rpBuilder.addEdge(root, m));
requiresTransitive.forEach(m -> rpBuilder.addEdge(root, m));

// requires transitive graph
Graph<Module> rbg = rpBuilder.build().reduce();

ModuleGraphBuilder gb = new ModuleGraphBuilder(configuration);
gb.addModule(root);
requires.stream()
.forEach(m -> gb.addEdge(root, m));
requires.forEach(m -> gb.addEdge(root, m));

// transitive reduction
Graph<Module> newGraph = gb.buildGraph().reduce(rbg);
Expand Down Expand Up @@ -310,7 +308,7 @@ private Map<String, Set<String>> unusedQualifiedExports() {
dependencyFinder.parse(mods.stream());

// adds to the qualified exports map if a module references it
mods.stream().forEach(m ->
mods.forEach(m ->
m.getDependencies()
.map(Dependency.Location::getPackageName)
.filter(qualifiedExports::containsKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void genDotFile(Path path, String name,
*/
private Graph<String> gengraph(Configuration cf) {
Graph.Builder<String> builder = new Graph.Builder<>();
cf.modules().stream()
cf.modules()
.forEach(rm -> {
String mn = rm.name();
builder.addNode(mn);
Expand Down Expand Up @@ -406,7 +406,7 @@ public void printNode(PrintWriter out, ModuleDescriptor md, Set<String> edges) {
.collect(toSet());

String mn = md.name();
edges.stream().forEach(dn -> {
edges.forEach(dn -> {
String attr;
if (dn.equals("java.base")) {
attr = "color=\"" + attributes.requiresMandatedColor() + "\"";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public boolean run(int maxDepth, boolean ignoreMissingDeps) throws IOException {
.distinct()
.forEach(m -> {
if (internalPkgs.containsKey(m)) {
internalPkgs.get(m).stream()
internalPkgs.get(m)
.forEach(pn -> writer.format(" %s/%s%s", m, pn, separator));
} else {
writer.format(" %s%s", m, separator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ private Graph<Module> buildGraph(Map<Module, Set<Module>> edges) {
Graph.Builder<Module> builder = new Graph.Builder<>();
Set<Module> visited = new HashSet<>();
Deque<Module> deque = new LinkedList<>();
edges.entrySet().stream().forEach(e -> {
edges.entrySet().forEach(e -> {
Module m = e.getKey();
deque.add(m);
e.getValue().stream().forEach(v -> {
e.getValue().forEach(v -> {
deque.add(v);
builder.addEdge(m, v);
});
Expand Down

0 comments on commit 7e92abe

Please sign in to comment.