8289804: Remove redundant stream() call before forEach in jdk.jshell

Reviewed-by: psandoz
This commit is contained in:
Andrey Turbanov 2022-07-19 11:32:30 +00:00
parent f5a7de8627
commit 2ff22087f2
3 changed files with 23 additions and 25 deletions

View File

@ -165,7 +165,7 @@ class Feedback {
} }
public void markModesReadOnly() { public void markModesReadOnly() {
modeMap.values().stream() modeMap.values()
.forEach(m -> m.readOnly = true); .forEach(m -> m.readOnly = true);
} }

View File

@ -341,14 +341,13 @@ public class JShellTool implements MessageHandler {
// return a new Options, with parameter options overriding receiver options // return a new Options, with parameter options overriding receiver options
Options override(Options newer) { Options override(Options newer) {
Options result = new Options(this); Options result = new Options(this);
newer.optMap.entrySet().stream() newer.optMap.forEach((key, value) -> {
.forEach(e -> { if (key.onlyOne) {
if (e.getKey().onlyOne) {
// Only one allowed, override last // Only one allowed, override last
result.optMap.put(e.getKey(), e.getValue()); result.optMap.put(key, value);
} else { } else {
// Additive // Additive
result.addAll(e.getKey(), e.getValue()); result.addAll(key, value);
} }
}); });
return result; return result;
@ -3543,8 +3542,7 @@ public class JShellTool implements MessageHandler {
errormsg(d.isError() ? "jshell.msg.error" : "jshell.msg.warning"); errormsg(d.isError() ? "jshell.msg.error" : "jshell.msg.warning");
List<String> disp = new ArrayList<>(); List<String> disp = new ArrayList<>();
displayableDiagnostic(source, d, disp); displayableDiagnostic(source, d, disp);
disp.stream() disp.forEach(l -> error("%s", l));
.forEach(l -> error("%s", l));
} }
} }

View File

@ -1008,8 +1008,8 @@ class Eval {
while (true) { while (true) {
state.debug(DBG_GEN, "compileAndLoad %s\n", ins); state.debug(DBG_GEN, "compileAndLoad %s\n", ins);
ins.stream().forEach(Unit::initialize); ins.forEach(Unit::initialize);
ins.stream().forEach(u -> u.setWrap(ins, ins)); ins.forEach(u -> u.setWrap(ins, ins));
if (ins.stream().anyMatch(u -> u.snippet().kind() == Kind.METHOD)) { if (ins.stream().anyMatch(u -> u.snippet().kind() == Kind.METHOD)) {
//if there is any method declaration, check the body of the method for //if there is any method declaration, check the body of the method for
@ -1052,24 +1052,24 @@ class Eval {
}); });
if (ins.addAll(overloads)) { if (ins.addAll(overloads)) {
ins.stream().forEach(Unit::initialize); ins.forEach(Unit::initialize);
ins.stream().forEach(u -> u.setWrap(ins, ins)); ins.forEach(u -> u.setWrap(ins, ins));
} }
} }
state.taskFactory.analyze(outerWrapSet(ins), at -> { 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 // corral any Snippets that need it
if (ins.stream().filter(u -> u.corralIfNeeded(ins)).count() > 0) { if (ins.stream().filter(u -> u.corralIfNeeded(ins)).count() > 0) {
// if any were corralled, re-analyze everything // if any were corralled, re-analyze everything
state.taskFactory.analyze(outerWrapSet(ins), cat -> { state.taskFactory.analyze(outerWrapSet(ins), cat -> {
ins.stream().forEach(u -> u.setCorralledDiagnostics(cat)); ins.forEach(u -> u.setCorralledDiagnostics(cat));
ins.stream().forEach(u -> u.setStatus(cat)); ins.forEach(u -> u.setStatus(cat));
return null; return null;
}); });
} else { } else {
ins.stream().forEach(u -> u.setStatus(at)); ins.forEach(u -> u.setStatus(at));
} }
return null; return null;
}); });
@ -1086,7 +1086,7 @@ class Eval {
success = true; success = true;
} else { } else {
// re-wrap with legit imports // 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 // generate class files for those capable
Result res = state.taskFactory.compile(outerWrapSet(legit), ct -> { Result res = state.taskFactory.compile(outerWrapSet(legit), ct -> {
@ -1116,9 +1116,9 @@ class Eval {
// loop by replacing all that have been replaced // loop by replacing all that have been replaced
if (!toReplace.isEmpty()) { if (!toReplace.isEmpty()) {
replaced.addAll(toReplace); replaced.addAll(toReplace);
replaced.stream().forEach(Unit::markForReplacement); replaced.forEach(Unit::markForReplacement);
//ensure correct classnames are set in the snippets: //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; return toReplace.isEmpty() ? Result.SUCESS : Result.FAILURE;
@ -1144,7 +1144,7 @@ class Eval {
// all classes that could not be directly loaded (because they // all classes that could not be directly loaded (because they
// are new) have been redefined, and no new dependnencies were // are new) have been redefined, and no new dependnencies were
// identified // identified
ins.stream().forEach(Unit::finish); ins.forEach(Unit::finish);
return ins; return ins;
} }
} }