www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14167] New: Improve performance of unstable remove()

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 puremagic.com
          Reporter: acehreli 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

--
Feb 10 2015