On Fri, 18 Aug 2023 00:22:10 GMT, David Holmes <dhol...@openjdk.org> wrote:

>> Was it odd before or odd now?  What we want to do is compare pointers for a 
>> sort function.  This primitive_compare has been used in other places as an 
>> improvement.
>
> It is the name `primitive_compare` - I only previously saw it used for 
> integer types. Using it with pointers seems "wrong". Don't we have to convert 
> to `intptr_t` to compare pointers numerically anyway?

template<typename K> bool primitive_equals(const K& k0, const K& k1) {
  return k0 == k1;
}

template<typename K> int primitive_compare(const K& k0, const K& k1) {
  return ((k0 < k1) ? -1 : (k0 == k1) ? 0 : 1);
}


This is the primitive_compare we added with one of these patches.  This 
compares pointers and because of the template, it doesn't need to look like 
this:


int Symbol::fast_compare(const Symbol* other) const {
 return (((uintptr_t)this < (uintptr_t)other) ? -1
   : ((uintptr_t)this == (uintptr_t) other) ? 0 : 1);
}


I can file another RFE so that we can argue about the name.  The name was what 
we agreed upon earlier, and I showed it with primtiive_equals and 
primitive_hash because it provides the same sort of default pointer comparison.
Please file an RFE so that this can be discussed independently of this PR.  We 
can change them all at one time.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/15233#discussion_r1297892748

Reply via email to