Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 2 commits into from

Conversation

iklam
Copy link
Member

@iklam iklam commented Dec 9, 2020

Now that range-based for loops are allowed by the HotSpot Style Guide, 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<>.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

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

Reviewers

Download

$ git fetch https://git.openjdk.java.net/jdk pull/1707/head:pull/1707
$ git checkout pull/1707

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 9, 2020

👋 Welcome back iklam! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Dec 9, 2020

@iklam The following label will be automatically applied to this pull request:

  • hotspot

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the hotspot hotspot-dev@openjdk.org label Dec 9, 2020
@iklam iklam marked this pull request as ready for review December 9, 2020 01:36
@openjdk openjdk bot added the rfr Pull request is ready for review label Dec 9, 2020
@mlbridge
Copy link

mlbridge bot commented Dec 9, 2020

Webrevs

@openjdk
Copy link

openjdk bot commented Dec 9, 2020

@iklam This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

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

Reviewed-by: kbarrett, tschatzl, gziemski

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 4 new commits pushed to the master branch:

  • 164c55b: 8258056: jdk/javadoc/doclet/testHtmlTableTags/TestHtmlTableTags.java fails against jdk17
  • 42264b2: 8257971: (fs) Remove unused code from WindowsPath.subpath(begin, end)
  • 3342eca: 8258054: runtime/sealedClasses/GetPermittedSubclassesTest.java fails w/ jdk17
  • f574056: 8256424: Move ciSymbol::symbol_name() to ciSymbols::symbol_name()

Please see this link for an up-to-date comparison between the source branch of this pull request and the master branch.
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Dec 9, 2020
Copy link
Contributor

@tschatzl tschatzl left a comment

Choose a reason for hiding this comment

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

Lgtm

@gerard-ziemski
Copy link

I like the change very much.

Did you consider leaving the convenience symbol "vmSymbolsIterator" as is and then using it in the loop, so instead of:

for (vmSymbolID index : EnumRange<vmSymbolID>{}) {

we would have:

for (vmSymbolID index : vmSymbolsIterator) {

which would be more concise (but less self-documenting I guess) and more similar to:

for (JVMFlagOrigin origin : range) {

@iklam
Copy link
Member Author

iklam commented Dec 9, 2020

I like the change very much.

Did you consider leaving the convenience symbol "vmSymbolsIterator" as is and then using it in the loop, so instead of:

for (vmSymbolID index : EnumRange<vmSymbolID>{}) {

we would have:

for (vmSymbolID index : vmSymbolsIterator) {

which would be more concise (but less self-documenting I guess) and more similar to:

for (JVMFlagOrigin origin : range) {

Hi Gerard, thanks for the review.

vmSymbolsIterator is the "cursor" type. I think you meant this:

for (vmSymbolID index : vmSymbolsRange{}) {...}

which is probably less readable, because you have to find out what vmSymbolsRange actually is.

I think the following pattern is easier to read. It will also make the iteration of different enum types more consistent. Iteration of any enum type E can be done the same way with EnumRange<E>. You don't need to invent a new ERange type.

for (MyEnumType e : EnumRange<MyEnumType>{}) {...}`

Note that the {} is required here because we need to construct an instance of EnumRange<MyEnumType> with its no-arg constructor. You can also use () but I think that would be less readable -- it's not clear whether you are calling a function or constructing an object. With {}, it's clear that we are making an initialization with the brace operator.

You can also initialize a non-default range with EnumRange<MyEnumType>{start, end}, etc.

@iklam
Copy link
Member Author

iklam commented Dec 10, 2020

/integrate

@openjdk openjdk bot closed this Dec 10, 2020
@openjdk openjdk bot added integrated Pull request has been integrated and removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Dec 10, 2020
@openjdk
Copy link

openjdk bot commented Dec 10, 2020

@iklam Since your change was applied there have been 4 commits pushed to the master branch:

  • 164c55b: 8258056: jdk/javadoc/doclet/testHtmlTableTags/TestHtmlTableTags.java fails against jdk17
  • 42264b2: 8257971: (fs) Remove unused code from WindowsPath.subpath(begin, end)
  • 3342eca: 8258054: runtime/sealedClasses/GetPermittedSubclassesTest.java fails w/ jdk17
  • f574056: 8256424: Move ciSymbol::symbol_name() to ciSymbols::symbol_name()

Your commit was automatically rebased without conflicts.

Pushed as commit 80dac5a.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot hotspot-dev@openjdk.org integrated Pull request has been integrated
4 participants