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-boun...@openjdk.java.net> on behalf of 
Martin Buchholz <marti...@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.san...@oracle.com> wrote:

>
>
> On Apr 30, 2018, at 11:18 AM, Martin Buchholz <marti...@google.com> wrote:
>
>
>
> On Mon, Apr 30, 2018 at 10:35 AM, Paul Sandoz <paul.san...@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.

Reply via email to