9
9
*/
10
10
module core.internal.array.construction ;
11
11
12
- import core.internal.traits : Unqual;
13
-
14
12
/**
15
13
* Does array initialization (not assignment) from another array of the same element type.
16
14
* Params:
@@ -23,8 +21,7 @@ import core.internal.traits : Unqual;
23
21
* purity, and throwabilty checks. To prevent breaking existing code, this function template
24
22
* is temporarily declared `@trusted` until the implementation can be brought up to modern D expectations.
25
23
*/
26
- Tarr1 _d_arrayctor (Tarr1 : T1 [], Tarr2 : T2 [], T1 , T2 )(scope Tarr2 from, size_t length) @trusted
27
- if (is (Unqual! T1 == Unqual! T2 ))
24
+ T[] _d_arrayctor (Tarr : T[], T)(scope Tarr from, size_t length) @trusted
28
25
{
29
26
pragma (inline, false );
30
27
import core.internal.traits : hasElaborateCopyConstructor, Unqual;
@@ -33,15 +30,10 @@ Tarr1 _d_arrayctor(Tarr1 : T1[], Tarr2 : T2[], T1, T2)(scope Tarr2 from, size_t
33
30
import core.stdc.stdint : uintptr_t ;
34
31
debug (PRINTF ) import core.stdc.stdio : printf;
35
32
36
- debug (PRINTF ) printf(" _d_arrayctor(to = %p,%d, from = %p,%d) size = %d\n " , from.ptr, from.length, to.ptr, to.length, T1 .tsize);
33
+ debug (PRINTF ) printf(" _d_arrayctor(to = %p,%d, from = %p,%d) size = %d\n " , from.ptr, from.length, to.ptr, to.length, T .tsize);
37
34
38
- Tarr1 to;
39
- // Check if Tarr1 is a dynamic array.
40
- // Otherwise, to.length is already set.
41
- static if (__traits(compiles, {to.length = length;}))
42
- {
43
- to.length = length;
44
- }
35
+ T[] to;
36
+ to.length = length;
45
37
46
38
void [] vFrom = (cast (void * )from.ptr)[0 .. from.length];
47
39
void [] vTo = (cast (void * )to.ptr)[0 .. to.length];
@@ -57,11 +49,13 @@ Tarr1 _d_arrayctor(Tarr1 : T1[], Tarr2 : T2[], T1, T2)(scope Tarr2 from, size_t
57
49
(cast (Type)&enforceRawArraysConformableNogc)(action, elementSize, a1, a2, false );
58
50
}
59
51
60
- enforceRawArraysConformable(" initialization" , T1 .sizeof, vFrom, vTo);
52
+ enforceRawArraysConformable(" initialization" , T .sizeof, vFrom, vTo);
61
53
62
- static if (hasElaborateCopyConstructor! T1 )
54
+ static if (hasElaborateCopyConstructor! T )
63
55
{
64
- size_t i;
56
+ // Use uint instead of size_t as a temporary workaround until this bug is fixed:
57
+ // https://issues.dlang.org/show_bug.cgi?id=22372
58
+ uint i;
65
59
try
66
60
{
67
61
for (i = 0 ; i < to.length; i++ )
@@ -73,7 +67,7 @@ Tarr1 _d_arrayctor(Tarr1 : T1[], Tarr2 : T2[], T1, T2)(scope Tarr2 from, size_t
73
67
*/
74
68
while (i-- )
75
69
{
76
- auto elem = cast (Unqual! T1 * )&to[i];
70
+ auto elem = cast (Unqual! T * )&to[i];
77
71
destroy (* elem);
78
72
}
79
73
@@ -83,7 +77,7 @@ Tarr1 _d_arrayctor(Tarr1 : T1[], Tarr2 : T2[], T1, T2)(scope Tarr2 from, size_t
83
77
else
84
78
{
85
79
// blit all elements at once
86
- memcpy(cast (void * ) to.ptr, from.ptr, to.length * T1 .sizeof);
80
+ memcpy(cast (void * ) to.ptr, from.ptr, to.length * T .sizeof);
87
81
}
88
82
89
83
return to;
@@ -101,7 +95,7 @@ Tarr1 _d_arrayctor(Tarr1 : T1[], Tarr2 : T2[], T1, T2)(scope Tarr2 from, size_t
101
95
102
96
S[4 ] arr1;
103
97
S[4 ] arr2 = [S(0 ), S(1 ), S(2 ), S(3 )];
104
- arr1 = _d_arrayctor! (S[ 4 ]) (arr2[], arr1.length);
98
+ arr1 = _d_arrayctor(arr2[], arr1.length);
105
99
106
100
assert (counter == 4 );
107
101
assert (arr1 == arr2);
@@ -124,7 +118,7 @@ Tarr1 _d_arrayctor(Tarr1 : T1[], Tarr2 : T2[], T1, T2)(scope Tarr2 from, size_t
124
118
125
119
S[4 ] arr1;
126
120
S[4 ] arr2 = [S(0 ), S(1 ), S(2 ), S(3 )];
127
- arr1 = _d_arrayctor! (S[ 4 ]) (arr2[], arr1.length);
121
+ arr1 = _d_arrayctor(arr2[], arr1.length);
128
122
129
123
assert (counter == 4 );
130
124
assert (arr1 == arr2);
@@ -150,7 +144,7 @@ Tarr1 _d_arrayctor(Tarr1 : T1[], Tarr2 : T2[], T1, T2)(scope Tarr2 from, size_t
150
144
{
151
145
Throw[4 ] a;
152
146
Throw[4 ] b = [Throw(1 ), Throw(2 ), Throw(3 ), Throw(4 )];
153
- a = _d_arrayctor! (Throw[ 4 ]) (b[], a.length);
147
+ a = _d_arrayctor(b[], a.length);
154
148
}
155
149
catch (Exception )
156
150
{
@@ -175,7 +169,7 @@ Tarr1 _d_arrayctor(Tarr1 : T1[], Tarr2 : T2[], T1, T2)(scope Tarr2 from, size_t
175
169
{
176
170
NoThrow[4 ] a;
177
171
NoThrow[4 ] b = [NoThrow(1 ), NoThrow(2 ), NoThrow(3 ), NoThrow(4 )];
178
- a = _d_arrayctor! (NoThrow[ 4 ]) (b[], a.length);
172
+ a = _d_arrayctor(b[], a.length);
179
173
}
180
174
catch (Exception )
181
175
{
@@ -199,6 +193,7 @@ Tarr1 _d_arrayctor(Tarr1 : T1[], Tarr2 : T2[], T1, T2)(scope Tarr2 from, size_t
199
193
void _d_arraysetctor (Tarr : T[], T)(scope Tarr p, scope ref T value) @trusted
200
194
{
201
195
pragma (inline, false );
196
+ import core.internal.traits : Unqual;
202
197
import core.lifetime : copyEmplace;
203
198
204
199
size_t i;
@@ -281,7 +276,7 @@ void _d_arraysetctor(Tarr : T[], T)(scope Tarr p, scope ref T value) @trusted
281
276
{
282
277
Throw[4 ] a;
283
278
Throw[4 ] b = [Throw(1 ), Throw(2 ), Throw(3 ), Throw(4 )];
284
- a = _d_arrayctor! (Throw[ 4 ]) (b[], a.length);
279
+ a = _d_arrayctor(b[], a.length);
285
280
}
286
281
catch (Exception )
287
282
{
0 commit comments