Integrated: 8257912: Convert enum iteration to use range-based for loops

Ioi Lam iklam at openjdk.java.net
Thu Dec 10 20:35:57 UTC 2020


On Wed, 9 Dec 2020 01:34:16 GMT, Ioi Lam <iklam at openjdk.org> wrote:

> Now that [range-based for loops](https://github.com/openjdk/jdk/pull/1488) are allowed by the [HotSpot Style Guide](https://github.com/openjdk/jdk/blob/52ab72127ddc3ca6575d9d58503ec39c5dff7ab1/doc/hotspot-style.md), I have converted the more verbose syntax:
> 
> for (vmIntrinsicsIterator it = vmIntrinsicsRange.begin(); it != vmIntrinsicsRange.end(); ++it) {
>   vmIntrinsicID index = *it;
>   nt[as_int(index)] = string;
> }
> 
> to
> 
>   for (vmIntrinsicID index : EnumRange<vmIntrinsicID>{}) {
>     nt[as_int(index)] = string;
>   }
> 
> I also removed the "convenient" declarations such as `vmIntrinsicsRange` and `vmIntrinsicsIterator` -- these are useful only when writing a traditional for loop, and are probably confusing to everyone else.  I've left examples in enumIterator.hpp in case anyone wants to write a traditional for loop.
> 
> I also added gtest cases for using range-based for loops with `EnumRange<>`.

This pull request has now been integrated.

Changeset: 80dac5a8
Author:    Ioi Lam <iklam at openjdk.org>
URL:       https://git.openjdk.java.net/jdk/commit/80dac5a8
Stats:     119 lines in 10 files changed: 71 ins; 24 del; 24 mod

8257912: Convert enum iteration to use range-based for loops

Reviewed-by: kbarrett, tschatzl, gziemski

-------------

PR: https://git.openjdk.java.net/jdk/pull/1707


More information about the hotspot-dev mailing list