Dynamic array comparison optimization: check for equal pointers?
Steven Schveighoffer
schveiguy at gmail.com
Tue Jun 2 21:18:40 UTC 2020
On 6/2/20 3:38 PM, Johan wrote:
> Hi all,
> I thought that we optimized dynamic array comparison with a check to
> see if the pointers are equal, but I don't see it in our array
> comparison implementation in druntime. Quick checking of glibc memcmp
> also showed that there is no short circuit for when the pointers of the
> slices are equal.
>
> I was expecting something like:
> ```
> if ( sizes are not equal )
> return false;
> if ( pointers are equal )
> return true;
> return memcmp;
> ```
>
> I am surprised that memcmp itself does not implement the pointers are
> equal check. Is there a big impact of adding the shortcircuit check to
> prevent scanning memory?
>
I thought I remembered this being true, but maybe it was for class
instances? Looking back in history, it seems prior to 2017, it was done
by the compiler generating the code instead of a template, but seems
like it did not include the pointer check.
-Steve
More information about the Digitalmars-d
mailing list