RFR: 8257466: Improve enum iteration

Kim Barrett kbarrett at openjdk.java.net
Wed Dec 2 02:15:05 UTC 2020


On Tue, 1 Dec 2020 22:23:51 GMT, Ioi Lam <iklam at openjdk.org> wrote:

>> Please review this collection of improvements to the recently added enum
>> iteration facility. These improvements are based on usage in some
>> in-development changes.
>> 
>> (1) Added EnumType nested type to EnumRange and EnumIterator. It is an alias
>> for the enum type that is a template parameter for those classes. This is
>> useful when dealing with a range or iterator whose associated enum type is
>> not known because the range/iterator is a template parameter.
>> 
>> (2) Added EnumRange<T>::index(T), which converts the argument enumerator to
>> a zero-based index into the range of values. This is useful when mapping
>> from an enumerator to a corresponding array index, for example.
>> 
>> (3) Allow enum range bounds to be specified using start and (exclusive) end
>> integral (underlying type) values. This is useful when dealing with enums
>> that are just value ranges and don't have named enumerators. As part of
>> this, changes the enum iteration traits mechanism to use start/end rather
>> than first/last, as that seems to be a little easier to deal with.
>> 
>> (4) Added accessors for the first and last enumerator values of a range.
>> 
>> (5) Added gtest for enum iteration.
>> 
>> Testing: tier1
>
> src/hotspot/share/utilities/enumIterator.hpp line 115:
> 
>> 113:     static constexpr EnumeratorRangeImpl::Underlying<T> _start =        \
>> 114:       EnumeratorRangeImpl::underlying<T>(Start);                        \
>> 115:     static constexpr EnumeratorRangeImpl::Underlying<T> _end =          \
> 
> Why do we need to call `underlying<T>(Start)` here? Can it be simplified as 
> static constexpr EnumeratorRangeImpl::Underlying<T> _start = Start;
> or
> static constexpr EnumeratorRangeImpl::Underlying<T> _start {Start};

I'd earlier considered requiring the type of Start and End be Underlying<T> rather than convertible to that.  The underlying() function is a partial remnant of that.  I'll remove it.

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

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


More information about the hotspot-dev mailing list