[Issue 18239] New: std.experimental.allocator fillWithMemcpy could use memset when T.sizeof==1
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Jan 15 18:15:48 UTC 2018
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 at puremagic.com
Reporter: n8sh.secondary at 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.
--
More information about the Digitalmars-d-bugs
mailing list