RFR: 8303621: BitMap::iterate should support lambdas and other function objects [v2]

Kim Barrett kbarrett at openjdk.org
Tue Mar 7 10:01:47 UTC 2023


On Tue, 7 Mar 2023 07:39:50 GMT, Stefan Karlsson <stefank at openjdk.org> wrote:

>> Kim Barrett has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   improve description of iterate
>
> src/hotspot/share/utilities/bitMap.inline.hpp line 273:
> 
>> 271:     }
>> 272:   }
>> 273: }
> 
> IMHO, this is an eyesore that I prefer if it could be hidden away a bit. Could we create an `invoke` function that that calls this, and change the code to:
> 
> template <typename Function>
> inline bool BitMap::iterate(Function function, idx_t beg, idx_t end) const {
>   for (idx_t index = beg; true; ++index) {
>     index = get_next_one_offset(index, end);
>     if (index >= end) {
>       return true;
>     } else if (!invoke(function, index)) {
>       return false;
>     }
>   }
> }
> 
> 
> And also add a comment why we need IterateInvoker?

I added a local function object so that template clutter wasn't all right in the middle of the function.
Making it a member function instead seemed to just push around the deck chairs.
Added comment, and also fixed a lurking, probably never to be hit, bug that we were stopping early if
ReturnType::operator! returned true, rather than if the converted to bool result was false.

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

PR: https://git.openjdk.org/jdk/pull/12876


More information about the hotspot-dev mailing list