www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18239] New: std.experimental.allocator fillWithMemcpy could

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

          Issue ID: 18239
           Summary: std.experimental.allocator fillWithMemcpy could use
                    memset when T.sizeof==1
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: n8sh.secondary hotmail.com

Current function in std.experimental.allocator.package:
```
private void fillWithMemcpy(T)(void[] array, auto ref T filler) nothrow
{
    import core.stdc.string : memcpy;
    import std.algorithm.comparison : min;
    if (!array.length) return;
    memcpy(array.ptr, &filler, T.sizeof);
    // Fill the array from the initialized portion of itself exponentially.
    for (size_t offset = T.sizeof; offset < array.length; )
    {
        size_t extent = min(offset, array.length - offset);
        memcpy(array.ptr + offset, array.ptr, extent);
        offset += extent;
    }
}
```

When T.sizeof==1 we could use memset instead.

If this change is made it might be a good idea to change the name of the
function to avoid an implicit contract that it uses the memcpy function.

--
Jan 15