RFR: Here are some easy patches
Michael Rasmussen
Michael.Rasmussen at roguewave.com
Wed May 2 20:51:46 UTC 2018
Hi Martin,
Did you consider using Class::isArray in the loop? Something like the following:
for (Object element : a) {
final int elementHash;
if (element == null) {
elementHash = 0;
}
else {
final Class<?> cl = element.getClass();
if (!cl.isArray())
elementHash = element.hashCode();
else if (element instanceof Object[])
elementHash = deepHashCode((Object[]) element);
else
elementHash = primitiveArrayHashCode(element, cl.getComponentType());
}
result = 31 * result + elementHash;
}
In my quick JMH test running on Java 10, it improved the performance with your test array (Object[100000] full of Integers) from 244 us/op to 160 us/op (vs current JDK: 399 us/op).
/Michael
________________________________
From: core-libs-dev <core-libs-dev-bounces at openjdk.java.net> on behalf of Martin Buchholz <martinrb at google.com>
Sent: 02 May 2018 21:17:19
To: Paul Sandoz
Cc: core-libs-dev
Subject: Re: RFR: Here are some easy patches
Hi Paul,
On Mon, Apr 30, 2018 at 2:03 PM, Paul Sandoz <paul.sandoz at oracle.com> wrote:
>
>
> On Apr 30, 2018, at 11:18 AM, Martin Buchholz <martinrb at google.com> wrote:
>
>
>
> On Mon, Apr 30, 2018 at 10:35 AM, Paul Sandoz <paul.sandoz at oracle.com>
> wrote:
>
>> An obvious optimization:
>>
>> 8202398: Optimize Arrays.deepHashCode
>> http://cr.openjdk.java.net/~martin/webrevs/jdk/deepHashCode-optimize/
>> https://bugs.openjdk.java.net/browse/JDK-8202398
>>
>> I would prefer that the deeply nested ternary expressions be changed to a
>> more expected if/else if/else
>>
>
> My brain much prefers code transforming tabular data to "look tabular".
>
>
>
> I think you will like expression switch :-) in the interim i would stick
> with the less eyebrow raising syntax.
>
>
I'm going to claim committer's privilege and check in with my preferred
tabular style. You can rewrite using suburban sprawl style when us
dinosaurs from the last milllenium have gone extinct.
More information about the core-libs-dev
mailing list