Skip to content

std.array.replaceInPlace: Use memmove when replacement increases length#11056

Open
bscuron wants to merge 1 commit into
dlang:masterfrom
bscuron:replaceInPlace
Open

std.array.replaceInPlace: Use memmove when replacement increases length#11056
bscuron wants to merge 1 commit into
dlang:masterfrom
bscuron:replaceInPlace

Conversation

@bscuron

@bscuron bscuron commented Jul 5, 2026

Copy link
Copy Markdown
$ cat main.d
import std.stdio;
import std.datetime.stopwatch;
import std.datetime;
import std.array;

void main()
{
  auto res = benchmark!(test)(100_000_000);
  auto dur = res[0].total!"msecs";
  writeln(dur);
}

void test()
{
  int[] xs = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
  xs.replaceInPlace(5, 10, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
}
$ dmd -boundscheck=off -release main.d
$ ./main.exe
17990 (BEFORE)
$ dmd -boundscheck=off -release -I./projects/phobos -L./projects/phobos/phobos64.lib main.d
$ ./main.exe
15598 (AFTER)

@bscuron bscuron requested a review from PetarKirov as a code owner July 5, 2026 03:40
@bscuron bscuron changed the title std.array: Use memmove when replacement increases length std.array.replaceInPlace: Use memmove when replacement increases length Jul 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants