mirror of
https://github.com/dlang/phobos.git
synced 2025-04-27 13:40:20 +03:00
Issue 7444 - Require [] for array copies too
This commit is contained in:
parent
45f23d90f1
commit
28dedee456
10 changed files with 29 additions and 29 deletions
|
@ -6003,7 +6003,7 @@ if (isInputRange!Range1 && isOutputRange!(Range2, ElementType!Range1))
|
||||||
// generic implementation.
|
// generic implementation.
|
||||||
enforce(target.length >= source.length,
|
enforce(target.length >= source.length,
|
||||||
"Cannot copy a source array into a smaller target array.");
|
"Cannot copy a source array into a smaller target array.");
|
||||||
target[0..source.length] = source;
|
target[0..source.length] = source[];
|
||||||
|
|
||||||
return target[source.length..$];
|
return target[source.length..$];
|
||||||
}
|
}
|
||||||
|
|
|
@ -1778,7 +1778,7 @@ void replaceInPlace(T, Range)(ref T[] array, size_t from, size_t to, Range stuff
|
||||||
{
|
{
|
||||||
// replacement reduces length
|
// replacement reduces length
|
||||||
immutable stuffEnd = from + stuff.length;
|
immutable stuffEnd = from + stuff.length;
|
||||||
array[from .. stuffEnd] = stuff;
|
array[from .. stuffEnd] = stuff[];
|
||||||
array = remove(array, tuple(stuffEnd, to));
|
array = remove(array, tuple(stuffEnd, to));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1957,7 +1957,7 @@ body
|
||||||
auto result = new T[s.length - slice.length + replacement.length];
|
auto result = new T[s.length - slice.length + replacement.length];
|
||||||
immutable so = slice.ptr - s.ptr;
|
immutable so = slice.ptr - s.ptr;
|
||||||
result[0 .. so] = s[0 .. so];
|
result[0 .. so] = s[0 .. so];
|
||||||
result[so .. so + replacement.length] = replacement;
|
result[so .. so + replacement.length] = replacement[];
|
||||||
result[so + replacement.length .. result.length] =
|
result[so + replacement.length .. result.length] =
|
||||||
s[so + slice.length .. s.length];
|
s[so + slice.length .. s.length];
|
||||||
|
|
||||||
|
@ -2205,9 +2205,9 @@ Appends an entire range to the managed array.
|
||||||
immutable len = _data.arr.length;
|
immutable len = _data.arr.length;
|
||||||
immutable newlen = len + items.length;
|
immutable newlen = len + items.length;
|
||||||
_data.arr = _data.arr.ptr[0..newlen];
|
_data.arr = _data.arr.ptr[0..newlen];
|
||||||
static if(is(typeof(_data.arr[] = items)))
|
static if(is(typeof(_data.arr[] = items[])))
|
||||||
{
|
{
|
||||||
_data.arr.ptr[len..newlen] = items;
|
_data.arr.ptr[len..newlen] = items[];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -440,8 +440,8 @@ struct MD5
|
||||||
uint index, padLen;
|
uint index, padLen;
|
||||||
|
|
||||||
//Save number of bits
|
//Save number of bits
|
||||||
bits[0 .. 4] = nativeToLittleEndian((cast(uint*)&_count)[0]);
|
bits[0 .. 4] = nativeToLittleEndian((cast(uint*)&_count)[0])[];
|
||||||
bits[4 .. 8] = nativeToLittleEndian((cast(uint*)&_count)[1]);
|
bits[4 .. 8] = nativeToLittleEndian((cast(uint*)&_count)[1])[];
|
||||||
|
|
||||||
//Pad out to 56 mod 64
|
//Pad out to 56 mod 64
|
||||||
index = (cast(uint)_count >> 3) & (64 - 1);
|
index = (cast(uint)_count >> 3) & (64 - 1);
|
||||||
|
@ -452,10 +452,10 @@ struct MD5
|
||||||
put(bits);
|
put(bits);
|
||||||
|
|
||||||
//Store state in digest
|
//Store state in digest
|
||||||
data[0 .. 4] = nativeToLittleEndian(_state[0]);
|
data[0 .. 4] = nativeToLittleEndian(_state[0])[];
|
||||||
data[4 .. 8] = nativeToLittleEndian(_state[1]);
|
data[4 .. 8] = nativeToLittleEndian(_state[1])[];
|
||||||
data[8 .. 12] = nativeToLittleEndian(_state[2]);
|
data[8 .. 12] = nativeToLittleEndian(_state[2])[];
|
||||||
data[12 .. 16] = nativeToLittleEndian(_state[3]);
|
data[12 .. 16] = nativeToLittleEndian(_state[3])[];
|
||||||
|
|
||||||
/* Zeroize sensitive information. */
|
/* Zeroize sensitive information. */
|
||||||
start();
|
start();
|
||||||
|
|
|
@ -585,8 +585,8 @@ struct RIPEMD160
|
||||||
uint index, padLen;
|
uint index, padLen;
|
||||||
|
|
||||||
//Save number of bits
|
//Save number of bits
|
||||||
bits[0 .. 4] = nativeToLittleEndian((cast(uint*)&_count)[0]);
|
bits[0 .. 4] = nativeToLittleEndian((cast(uint*)&_count)[0])[];
|
||||||
bits[4 .. 8] = nativeToLittleEndian((cast(uint*)&_count)[1]);
|
bits[4 .. 8] = nativeToLittleEndian((cast(uint*)&_count)[1])[];
|
||||||
|
|
||||||
//Pad out to 56 mod 64
|
//Pad out to 56 mod 64
|
||||||
index = (cast(uint)_count >> 3) & (64 - 1);
|
index = (cast(uint)_count >> 3) & (64 - 1);
|
||||||
|
@ -597,11 +597,11 @@ struct RIPEMD160
|
||||||
put(bits);
|
put(bits);
|
||||||
|
|
||||||
//Store state in digest
|
//Store state in digest
|
||||||
data[0 .. 4] = nativeToLittleEndian(_state[0]);
|
data[0 .. 4] = nativeToLittleEndian(_state[0])[];
|
||||||
data[4 .. 8] = nativeToLittleEndian(_state[1]);
|
data[4 .. 8] = nativeToLittleEndian(_state[1])[];
|
||||||
data[8 .. 12] = nativeToLittleEndian(_state[2]);
|
data[8 .. 12] = nativeToLittleEndian(_state[2])[];
|
||||||
data[12 .. 16] = nativeToLittleEndian(_state[3]);
|
data[12 .. 16] = nativeToLittleEndian(_state[3])[];
|
||||||
data[16 .. 20] = nativeToLittleEndian(_state[4]);
|
data[16 .. 20] = nativeToLittleEndian(_state[4])[];
|
||||||
|
|
||||||
/* Zeroize sensitive information. */
|
/* Zeroize sensitive information. */
|
||||||
start();
|
start();
|
||||||
|
|
|
@ -482,7 +482,7 @@ struct SHA1
|
||||||
|
|
||||||
/* Store state in digest */
|
/* Store state in digest */
|
||||||
for (auto i = 0; i < 5; i++)
|
for (auto i = 0; i < 5; i++)
|
||||||
data[i*4..(i+1)*4] = nativeToBigEndian(state[i]);
|
data[i*4..(i+1)*4] = nativeToBigEndian(state[i])[];
|
||||||
|
|
||||||
/* Zeroize sensitive information. */
|
/* Zeroize sensitive information. */
|
||||||
start();
|
start();
|
||||||
|
|
|
@ -92,7 +92,7 @@ class OutBuffer
|
||||||
void write(const(ubyte)[] bytes)
|
void write(const(ubyte)[] bytes)
|
||||||
{
|
{
|
||||||
reserve(bytes.length);
|
reserve(bytes.length);
|
||||||
data[offset .. offset + bytes.length] = bytes;
|
data[offset .. offset + bytes.length] = bytes[];
|
||||||
offset += bytes.length;
|
offset += bytes.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3785,7 +3785,7 @@ template BacktrackingMatcher(bool CTregex)
|
||||||
*cast(State*)&memory[lastState] =
|
*cast(State*)&memory[lastState] =
|
||||||
State(index, pc, counter, infiniteNesting);
|
State(index, pc, counter, infiniteNesting);
|
||||||
lastState += stateSize;
|
lastState += stateSize;
|
||||||
memory[lastState..lastState+2*matches.length] = cast(size_t[])matches[];
|
memory[lastState..lastState+2*matches.length] = (cast(size_t[])matches)[];
|
||||||
lastState += 2*matches.length;
|
lastState += 2*matches.length;
|
||||||
debug(fred_matching)
|
debug(fred_matching)
|
||||||
writefln("Saved(pc=%s) front: %s src: %s"
|
writefln("Saved(pc=%s) front: %s src: %s"
|
||||||
|
|
|
@ -270,7 +270,7 @@ body
|
||||||
|
|
||||||
// Need to make a copy
|
// Need to make a copy
|
||||||
auto copy = new char[s.length + 1];
|
auto copy = new char[s.length + 1];
|
||||||
copy[0..s.length] = s;
|
copy[0..s.length] = s[];
|
||||||
copy[s.length] = 0;
|
copy[s.length] = 0;
|
||||||
|
|
||||||
return assumeUnique(copy).ptr;
|
return assumeUnique(copy).ptr;
|
||||||
|
|
|
@ -1103,7 +1103,7 @@ UUID randomUUID(RNG)(ref RNG randomGen) if(isUniformRNG!(RNG) &&
|
||||||
{
|
{
|
||||||
randomGen.popFront();
|
randomGen.popFront();
|
||||||
immutable randomValue = randomGen.front;
|
immutable randomValue = randomGen.front;
|
||||||
u.data[i .. i + elemSize] = *cast(ubyte[elemSize]*)&randomValue;
|
u.data[i .. i + elemSize] = (*cast(ubyte[elemSize]*)&randomValue)[];
|
||||||
}
|
}
|
||||||
|
|
||||||
//set variant
|
//set variant
|
||||||
|
|
12
std/zip.d
12
std/zip.d
|
@ -233,9 +233,9 @@ class ZipArchive
|
||||||
putUshort(i + 28, cast(ushort)de.extra.length);
|
putUshort(i + 28, cast(ushort)de.extra.length);
|
||||||
i += 30;
|
i += 30;
|
||||||
|
|
||||||
data[i .. i + de.name.length] = cast(ubyte[])de.name[];
|
data[i .. i + de.name.length] = (cast(ubyte[])de.name)[];
|
||||||
i += de.name.length;
|
i += de.name.length;
|
||||||
data[i .. i + de.extra.length] = cast(ubyte[])de.extra[];
|
data[i .. i + de.extra.length] = (cast(ubyte[])de.extra)[];
|
||||||
i += de.extra.length;
|
i += de.extra.length;
|
||||||
data[i .. i + de.compressedSize] = de.compressedData[];
|
data[i .. i + de.compressedSize] = de.compressedData[];
|
||||||
i += de.compressedSize;
|
i += de.compressedSize;
|
||||||
|
@ -264,11 +264,11 @@ class ZipArchive
|
||||||
putUint (i + 42, de.offset);
|
putUint (i + 42, de.offset);
|
||||||
i += 46;
|
i += 46;
|
||||||
|
|
||||||
data[i .. i + de.name.length] = cast(ubyte[])de.name[];
|
data[i .. i + de.name.length] = (cast(ubyte[])de.name)[];
|
||||||
i += de.name.length;
|
i += de.name.length;
|
||||||
data[i .. i + de.extra.length] = cast(ubyte[])de.extra[];
|
data[i .. i + de.extra.length] = (cast(ubyte[])de.extra)[];
|
||||||
i += de.extra.length;
|
i += de.extra.length;
|
||||||
data[i .. i + de.comment.length] = cast(ubyte[])de.comment[];
|
data[i .. i + de.comment.length] = (cast(ubyte[])de.comment)[];
|
||||||
i += de.comment.length;
|
i += de.comment.length;
|
||||||
numEntries++;
|
numEntries++;
|
||||||
}
|
}
|
||||||
|
@ -288,7 +288,7 @@ class ZipArchive
|
||||||
|
|
||||||
// Write archive comment
|
// Write archive comment
|
||||||
assert(i + comment.length == data.length);
|
assert(i + comment.length == data.length);
|
||||||
data[i .. data.length] = cast(ubyte[])comment[];
|
data[i .. data.length] = (cast(ubyte[])comment)[];
|
||||||
|
|
||||||
return cast(void[])data;
|
return cast(void[])data;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue