[Issue 10403] New: memchr optimization for std.algorithm.find

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jun 18 05:52:40 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10403

           Summary: memchr optimization for std.algorithm.find
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: tommitissari at hotmail.com


--- Comment #0 from Tommi <tommitissari at hotmail.com> 2013-06-18 05:52:38 PDT ---
Add an optimization for:

R find(alias pred = "a == b", R, E)(R haystack, E needle);

...to use the c function memchr when pred is the default "a == b" and...

CASE 1:
All of the following are true:

1) R is an array of elements of type char, byte, ubyte or an enum type whose
base type is one of those.
2) E is integral
3) For the element type of R:
alias Elem = ElementType!R;
...the following is true:
(Elem.min <= needle && needle <= Elem.max)
This is important because memchr only cares about bitwise equality. If the
value of needle is beyound the limits of possible values for type Elem, then we
know needle cannot be found within haystack and the function can just return
early without searching.

CASE 2:
All of the following are true:

1) R is an array of elements of type E
2) E.sizeof == 1
3) For type E equality means bitwise equality

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list