On Tuesday, 28 June 2016 at 03:11:26 UTC, Jay Norwood wrote:
On Tuesday, 28 June 2016 at 01:53:22 UTC, deadalnix wrote:
If we were in interview, I'd ask you "what does this returns if you pass it an empty string ?"


I'd say use this one instead, to avoid negative size_t. It is also a little faster for the same measurement.

nothrow pure size_t strlen2(const(char)* c) {
  if (c is null)
     return 0;
  const(char)* c_save = c;
  while (*c){ c+=4; }
  while (*c==0){ c--; }
  c++;
  return c - c_save;
}

2738
540
2744

If we were in an interview, I would insist.

Reply via email to