Dynamic array comparison optimization: check for equal pointers?

Stanislav Blinov stanislav.blinov at gmail.com
Wed Jun 3 00:35:47 UTC 2020


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.

For the third time, and let me be a little more explicit this 
time - if a program gives memcmp identical pointers so much as to 
warrant a test (which is found out by measuring) - the program is 
doing something wrong. *It* should do a test and not bother with 
memcmp at all. Or its logic needs to change so as to not have 
this problem in the first place. Same translates onto druntime's 
arrays.

There's no definitive answer to Johan's original question. It 
depends. On hardware. On data. Therefore, that check shouldn't be 
there, it should be delegated to someone capable of making such 
decision - to the user.


More information about the Digitalmars-d mailing list