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: [email protected]
          Reporter: [email protected]

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

--

Reply via email to