On Thu, 21 Dec 2023 14:47:43 GMT, ExE Boss <d...@openjdk.org> wrote:

>> Sergey Tsypanov has updated the pull request incrementally with one 
>> additional commit since the last revision:
>> 
>>   8322292: Tiny improvement
>
> src/java.base/share/classes/java/lang/runtime/ObjectMethods.java line 227:
> 
>> 225:             }
>> 226:             return rt1.isPrimitive() || rt1.isEnum() || rt1.isArray() ? 
>> 1 : Iterable.class.isAssignableFrom(rt1) ? -1 : 0;
>> 227:         });
> 
> The way this comparator is currently implemented, the `signum(c.compare(mh1, 
> mh2)) == -signum(c.compare(mh2, mh1))` assertion won’t hold, which will cause 
> the sorting to be unstable.

This should ensure stable ordering:
Suggestion:

        Arrays.sort(equalsGetters, (mh1, mh2) -> {
            var rt1 = mh1.type().returnType();
            var rt2 = mh2.type().returnType();
            return Integer.compare(
                rt1.isPrimitive() || rt1.isEnum() || rt1.isArray() ? 1 : 
Iterable.class.isAssignableFrom(rt1) ? -1 : 0,
                rt2.isPrimitive() || rt2.isEnum() || rt2.isArray() ? 1 : 
Iterable.class.isAssignableFrom(rt2) ? -1 : 0
            );
        });

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

PR Review Comment: https://git.openjdk.org/jdk/pull/17143#discussion_r1434173126

Reply via email to