[Issue 14167] New: Improve performance of unstable remove()

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Feb 10 15:46:11 PST 2015


https://issues.dlang.org/show_bug.cgi?id=14167

          Issue ID: 14167
           Summary: Improve performance of unstable remove()
           Product: D
           Version: future
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: Phobos
          Assignee: nobody at puremagic.com
          Reporter: acehreli at yahoo.com

There is a potential improvement to std.algorithm.remove() for its 
SwapStrategy.unstable version:

    static if (s != SwapStrategy.stable)
    {
        for (;!range.empty;)
        {
            if (!unaryFun!pred(range.front))
            {
                range.popFront();
                continue;
            }
            move(range.back, range.front);  // <-- *
            range.popBack();
            result.popBack();
        }
    }

The move on the marked line can be avoided if range.back does not satisfy the
predicate. In other words, why move the element to front just to popFront it in
the next iteration if it does not satisfy the predicate to begin with. :)

Ali

--


More information about the Digitalmars-d-bugs mailing list