Skip to content

Commit

Permalink
8289804: Remove redundant stream() call before forEach in jdk.jshell
Browse files Browse the repository at this point in the history
Reviewed-by: psandoz
  • Loading branch information
Andrey Turbanov committed Jul 19, 2022
1 parent f5a7de8 commit 2ff2208
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public boolean restoreEncodedModes(MessageHandler messageHandler, String encoded
}

public void markModesReadOnly() {
modeMap.values().stream()
modeMap.values()
.forEach(m -> m.readOnly = true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,16 +341,15 @@ void addAll(OptionKind kind, Collection<String> vals) {
// return a new Options, with parameter options overriding receiver options
Options override(Options newer) {
Options result = new Options(this);
newer.optMap.entrySet().stream()
.forEach(e -> {
if (e.getKey().onlyOne) {
// Only one allowed, override last
result.optMap.put(e.getKey(), e.getValue());
} else {
// Additive
result.addAll(e.getKey(), e.getValue());
}
});
newer.optMap.forEach((key, value) -> {
if (key.onlyOne) {
// Only one allowed, override last
result.optMap.put(key, value);
} else {
// Additive
result.addAll(key, value);
}
});
return result;
}
}
Expand Down Expand Up @@ -3543,8 +3542,7 @@ private void displayDiagnostics(String source, List<Diag> diagnostics) {
errormsg(d.isError() ? "jshell.msg.error" : "jshell.msg.warning");
List<String> disp = new ArrayList<>();
displayableDiagnostic(source, d, disp);
disp.stream()
.forEach(l -> error("%s", l));
disp.forEach(l -> error("%s", l));
}
}

Expand Down
24 changes: 12 additions & 12 deletions src/jdk.jshell/share/classes/jdk/jshell/Eval.java
Original file line number Diff line number Diff line change
Expand Up @@ -1008,8 +1008,8 @@ private Set<Unit> compileAndLoad(Set<Unit> ins) {
while (true) {
state.debug(DBG_GEN, "compileAndLoad %s\n", ins);

ins.stream().forEach(Unit::initialize);
ins.stream().forEach(u -> u.setWrap(ins, ins));
ins.forEach(Unit::initialize);
ins.forEach(u -> u.setWrap(ins, ins));

if (ins.stream().anyMatch(u -> u.snippet().kind() == Kind.METHOD)) {
//if there is any method declaration, check the body of the method for
Expand Down Expand Up @@ -1052,24 +1052,24 @@ public Void visitMethodInvocation(MethodInvocationTree node, Void p) {
});

if (ins.addAll(overloads)) {
ins.stream().forEach(Unit::initialize);
ins.stream().forEach(u -> u.setWrap(ins, ins));
ins.forEach(Unit::initialize);
ins.forEach(u -> u.setWrap(ins, ins));
}
}

state.taskFactory.analyze(outerWrapSet(ins), at -> {
ins.stream().forEach(u -> u.setDiagnostics(at));
ins.forEach(u -> u.setDiagnostics(at));

// corral any Snippets that need it
if (ins.stream().filter(u -> u.corralIfNeeded(ins)).count() > 0) {
// if any were corralled, re-analyze everything
state.taskFactory.analyze(outerWrapSet(ins), cat -> {
ins.stream().forEach(u -> u.setCorralledDiagnostics(cat));
ins.stream().forEach(u -> u.setStatus(cat));
ins.forEach(u -> u.setCorralledDiagnostics(cat));
ins.forEach(u -> u.setStatus(cat));
return null;
});
} else {
ins.stream().forEach(u -> u.setStatus(at));
ins.forEach(u -> u.setStatus(at));
}
return null;
});
Expand All @@ -1086,7 +1086,7 @@ public Void visitMethodInvocation(MethodInvocationTree node, Void p) {
success = true;
} else {
// re-wrap with legit imports
legit.stream().forEach(u -> u.setWrap(ins, legit));
legit.forEach(u -> u.setWrap(ins, legit));

// generate class files for those capable
Result res = state.taskFactory.compile(outerWrapSet(legit), ct -> {
Expand Down Expand Up @@ -1116,9 +1116,9 @@ public Void visitMethodInvocation(MethodInvocationTree node, Void p) {
// loop by replacing all that have been replaced
if (!toReplace.isEmpty()) {
replaced.addAll(toReplace);
replaced.stream().forEach(Unit::markForReplacement);
replaced.forEach(Unit::markForReplacement);
//ensure correct classnames are set in the snippets:
replaced.stream().forEach(u -> u.setWrap(ins, legit));
replaced.forEach(u -> u.setWrap(ins, legit));
}

return toReplace.isEmpty() ? Result.SUCESS : Result.FAILURE;
Expand All @@ -1144,7 +1144,7 @@ public Void visitMethodInvocation(MethodInvocationTree node, Void p) {
// all classes that could not be directly loaded (because they
// are new) have been redefined, and no new dependnencies were
// identified
ins.stream().forEach(Unit::finish);
ins.forEach(Unit::finish);
return ins;
}
}
Expand Down

1 comment on commit 2ff2208

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.