RFR: More cleanup patches

mandy chung mandy.chung at oracle.com
Sat Mar 31 01:12:16 UTC 2018



On 3/31/18 12:29 AM, Martin Buchholz wrote:
>
>
> On Fri, Mar 30, 2018 at 4:31 AM, mandy chung <mandy.chung at oracle.com 
> <mailto:mandy.chung at oracle.com>> wrote:
>
>
>     For this change, I am okay with most of the changes except I
>     prefer the while loop to the for-loop with the local variable
>     declaration.
>
>
> I prefer the idiom with the declaration in the for loop ("keep 
> variable scope as small as possible"), but reverting:
>
> diff --git 
> a/src/java.base/share/classes/jdk/internal/module/ModuleHashesBuilder.java 
> b/src/java.base/share/classes/jdk/internal/module/ModuleHashesBuilder.java
> --- 
> a/src/java.base/share/classes/jdk/internal/module/ModuleHashesBuilder.java
> +++ 
> b/src/java.base/share/classes/jdk/internal/module/ModuleHashesBuilder.java
> @@ -77,7 +77,8 @@
>          Graph.Builder<String> builder = new Graph.Builder<>();
>          Deque<ResolvedModule> todo = new 
> ArrayDeque<>(configuration.modules());
>          Set<ResolvedModule> visited = new HashSet<>();
> -        for (ResolvedModule rm; (rm = todo.poll()) != null; ) {
> +        ResolvedModule rm;
> +        while ((rm = todo.poll()) != null) {
>              if (visited.add(rm)) {
>                  builder.addNode(rm.name <http://rm.name>());
>                  for (ResolvedModule dm : rm.reads()) {
> @@ -211,7 +212,8 @@
>          public Set<T> dfs(Set<T> roots) {
>              ArrayDeque<T> todo = new ArrayDeque<>(roots);
>              Set<T> visited = new HashSet<>();
> -            for (T u; (u = todo.poll()) != null; ) {
> +            T u;
> +            while ((u = todo.poll()) != null) {
>                  if (visited.add(u) && contains(u)) {
>                      adjacentNodes(u).stream()
>                          .filter(v -> !visited.contains(v))
>

+1

Thanks.
Mandy


More information about the core-libs-dev mailing list