Searching strings with indexOf vs countUntil

Stanislav Blinov via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu May 25 12:47:13 PDT 2017


On Thursday, 25 May 2017 at 18:13:15 UTC, Anonymouse wrote:

> Part of the strings I'm working with can be assumed to be only 
> ASCII, yes. indexOf only wants strings or char[]s, but 
> interestingly if I use the same benchmark but have countUntil 
> work on raw ubyte[]s, it is faster. See 
> https://dpaste.dzfl.pl/2e095f7d18be.

There's a less ugly cast in std.string:

import std.string : representation;

//(cast(ubyte[])line).countUntil(cast(ubyte[])" :");
line.representation.countUntil(" :".representation);


More information about the Digitalmars-d-learn mailing list