Dynamic array comparison optimization: check for equal pointers?
Steven Schveighoffer
schveiguy at gmail.com
Wed Jun 3 01:10:55 UTC 2020
On 6/2/20 8:35 PM, Stanislav Blinov wrote:
> On Wednesday, 3 June 2020 at 00:04:43 UTC, Steven Schveighoffer wrote:
>
>>> Users can always write a compare_arrays_ptrcheck if so required, but
>>> they cannot "unwrite" druntime.
>>
>> I'm saying the compiler can unwrite druntime, if it knows a better way.
>>
>> Happens all the time with LDC, it will remove loops that it knows
>> don't do anything.
>>
>> And the upside is that compilers that don't do the "smarter" thing
>> will not needlessly call memcmp.
>
> ....Yes? And that will fall under a hypothetical case when the check
> just gets removed (or heck, inserted if it's faster). Leaving it in for
> all other cases when the compiler *can't* remove it. Make the best case
> better but the worst case worse? No thanks.
The worst case is opaque memcmp is called in all cases. No thanks. I'll
take a few extra cycles over that any day.
-Steve
More information about the Digitalmars-d
mailing list