On Tue, 1 Dec 2026 15:09:09 GMT, Per Minborg <[email protected]> wrote:

>> Please review this fix for `Set.ofLazy` and `Map.ofLazy` behaviour.
>> 
>> When looking up an object that is equal to a stored candidate but is a 
>> different instance,
>> `Set.contains()` and `Map.get()` pass the lookup argument to the computing 
>> function instead of the stored candidate.
>> 
>> This change stores the candidates in an array and uses the lookup index to 
>> retrieve the corresponding candidate before calling the computing function.
>> 
>> Regression tests have been added for both `Set` and `Map` to verify that the 
>> computing function receives the stored candidate.
>> 
>> Tests:
>> - `LazySetTest`
>> - `tier1`
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> Ok. So maybe I should hold off on a new PR and just share my thoughts here 
> @PeyaPeyaPeyang 
> 
> So, what do you think about adding a slimmed-down version of the backing 
> key-to-int map and where we can get both keys and values (`int`) from the 
> slimmed-down map? That way we don't have to have an extra array and I think 
> it might even be faster. Here is an outline:
> 
> 
>     private sealed interface ToIntMapWithSlots<K> {
>         // A nonnegative result identifies the slot for both accessors.
>         int findSlot(Object key);
>         K keyAt(int slot);
>         int valueAt(int slot);
>     }
> 
> 
> And then we could have two implementations: one for N entries and one for 
> just 1 entry (making it correspond to what we had before).
> 
> The `ToIntMapWithSlotsN` (or whatever it should be called) could have two 
> `@Stable` arrays:
>  * private final K[] keys;
>  * private final int[] indices;
> 
> We could use a trick where we put index + 1 in the `int` array to benefit 
> from stability. 
> 
> What do you think?

Hello again @minborg,

I've implemented the suggested approach.
The implementation now gets the stored key and its index in a single lookup.
I've confirmed that tier1 and `LazySetTest`/`LazyMapTest` passed.

Could you take a look at this change?

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

PR Comment: https://git.openjdk.org/jdk/pull/34144#issuecomment-7366748285

Reply via email to