Bug 18239 – std.experimental.allocator fillWithMemcpy could use memset when T.sizeof==1
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-01-15T18:15:48Z
Last change time
2018-01-17T21:36:38Z
Assigned to
No Owner
Creator
Nathan S.
Comments
Comment #0 by n8sh.secondary — 2018-01-15T18:15:48Z
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.
Comment #1 by n8sh.secondary — 2018-01-15T18:37:12Z
Could also use wmemset when T.sizeof == wint_t.sizeof
Comment #2 by n8sh.secondary — 2018-01-15T18:48:17Z
(In reply to Nathan S. from comment #1)
> Could also use wmemset when T.sizeof == wint_t.sizeof
Unfortunately core.stdc.wchar_.wmemset isn't marked as pure so this would cause some tests to fail.
Comment #3 by github-bugzilla — 2018-01-17T21:36:37Z