[Issue 17485] bringToFront and/or upperBound slow

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Jun 9 16:48:53 PDT 2017


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

--- Comment #2 from hsteoh at quickfur.ath.cx ---
More specifically, if (1) both ranges are built-in arrays, (2) they have the
same element type, and (3) the back range is a single element, we can optimize
this way:

If front and back are disjoint: (front.ptr > back.ptr && front.ptr +
front.length < back.ptr)

-------
ElementType!InputRange e1 = back[0];
back[0] = front[$-1];
memmove(front.ptr+1, front.ptr, front.length-1);
front[0] = e1;
-------

If back is part of front (i.e., front.ptr < back.ptr < front.ptr +
front.length):

--------
ElementType!InputRange e1 = back[0];
memmove(front.ptr+1, front.ptr, back.ptr - front.ptr);
front[0] = e1;
--------

--


More information about the Digitalmars-d-bugs mailing list