Bug 14167 – Improve performance of unstable remove()

Status
NEW
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2015-02-10T23:46:11Z
Last change time
2024-12-01T16:23:44Z
Assigned to
No Owner
Creator
Ali Cehreli
Moved to GitHub: phobos#9653 →

Comments

Comment #0 by acehreli — 2015-02-10T23:46:11Z
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
Comment #1 by robert.schadek — 2024-12-01T16:23:44Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/9653 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB