On Sat, 27 Jan 2024 07:52:56 GMT, David Alayachew <d...@openjdk.org> wrote:

>> Adding a function to Objects in order to facilitate equality checking and 
>> enhance readability. You simply specify the 2 objects that you want to check 
>> for equality, and then provide the functions which will be used to provide 
>> the values that we will check for equality.
>
> David Alayachew has updated the pull request incrementally with one 
> additional commit since the last revision:
> 
>   Rather than reiterating the precondition, let's explain why the method 
> failed

> I strongly disrecommend adding a library method that will become a 
> performance burden. This method is not helpful as it is hard to optimize; I 
> would recommend creating an alternative with this signature:
> 
> ```java
> public static <T> BiPredicate<T, T> equalsBy(List<Function<T, ?>> getters)
> ```
> 
> If this getters list is constant (like from `List.of`), JIT can actually 
> constant-fold the resulting predicate, making it much faster than your API 
> once inlined.
> 
> Your current notation doesn't offer any opportunity for JIT compiler to treat 
> the getters as a constant to perform optimizations.

Deal. Let me make the changes.

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

PR Comment: https://git.openjdk.org/jdk/pull/17603#issuecomment-1913269365

Reply via email to