4x faster strlen with 4 char sentinel

Jay Norwood via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Tue Jun 28 05:39:51 PDT 2016


On Tuesday, 28 June 2016 at 09:31:46 UTC, Sebastiaan Koppe wrote:
>> If we were in interview, I'd ask you "what does this returns 
>> if you pass it an empty string ?"
>
> Since no one is answering:
>
> It depends on the memory right before c. But if there is at 
> least one 0 right before it - which is quite likely - then you 
> get some crazy big number returned.

Yes, the test checked for 0 length but not with a preceding 0.  I 
posted the fix.

   if (c is null || *c==0)





More information about the Digitalmars-d-announce mailing list