mirror of
https://github.com/dlang/phobos.git
synced 2025-04-29 14:40:30 +03:00
zip & zlib: don't zero-fill buffers before writing to them
This commit is contained in:
parent
810ffe6990
commit
8ae499e963
2 changed files with 8 additions and 5 deletions
|
@ -414,7 +414,7 @@ final class ZipArchive
|
||||||
*/
|
*/
|
||||||
void[] build() @safe pure
|
void[] build() @safe pure
|
||||||
{
|
{
|
||||||
import std.array : array;
|
import std.array : array, uninitializedArray;
|
||||||
import std.algorithm.sorting : sort;
|
import std.algorithm.sorting : sort;
|
||||||
import std.string : representation;
|
import std.string : representation;
|
||||||
|
|
||||||
|
@ -449,7 +449,7 @@ final class ZipArchive
|
||||||
if (isZip64)
|
if (isZip64)
|
||||||
dataSize += eocd64LocLength + eocd64Length;
|
dataSize += eocd64LocLength + eocd64Length;
|
||||||
|
|
||||||
_data = new ubyte[dataSize];
|
_data = uninitializedArray!(ubyte[])(dataSize);
|
||||||
|
|
||||||
// Populate the data[]
|
// Populate the data[]
|
||||||
|
|
||||||
|
|
|
@ -201,8 +201,9 @@ in
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
import core.memory : GC;
|
import core.memory : GC;
|
||||||
|
import std.array : uninitializedArray;
|
||||||
auto destlen = srcbuf.length + ((srcbuf.length + 1023) / 1024) + 12;
|
auto destlen = srcbuf.length + ((srcbuf.length + 1023) / 1024) + 12;
|
||||||
auto destbuf = new ubyte[destlen];
|
auto destbuf = uninitializedArray!(ubyte[])(destlen);
|
||||||
auto err = etc.c.zlib.compress2(destbuf.ptr, &destlen, cast(ubyte *) srcbuf.ptr, srcbuf.length, level);
|
auto err = etc.c.zlib.compress2(destbuf.ptr, &destlen, cast(ubyte *) srcbuf.ptr, srcbuf.length, level);
|
||||||
if (err)
|
if (err)
|
||||||
{
|
{
|
||||||
|
@ -411,6 +412,7 @@ class Compress
|
||||||
const(void)[] compress(const(void)[] buf)
|
const(void)[] compress(const(void)[] buf)
|
||||||
{
|
{
|
||||||
import core.memory : GC;
|
import core.memory : GC;
|
||||||
|
import std.array : uninitializedArray;
|
||||||
int err;
|
int err;
|
||||||
ubyte[] destbuf;
|
ubyte[] destbuf;
|
||||||
|
|
||||||
|
@ -425,7 +427,7 @@ class Compress
|
||||||
inited = 1;
|
inited = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
destbuf = new ubyte[zs.avail_in + buf.length];
|
destbuf = uninitializedArray!(ubyte[])(zs.avail_in + buf.length);
|
||||||
zs.next_out = destbuf.ptr;
|
zs.next_out = destbuf.ptr;
|
||||||
zs.avail_out = to!uint(destbuf.length);
|
zs.avail_out = to!uint(destbuf.length);
|
||||||
|
|
||||||
|
@ -586,6 +588,7 @@ class UnCompress
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
import core.memory : GC;
|
import core.memory : GC;
|
||||||
|
import std.array : uninitializedArray;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (!inited)
|
if (!inited)
|
||||||
|
@ -604,7 +607,7 @@ class UnCompress
|
||||||
|
|
||||||
if (!destbufsize)
|
if (!destbufsize)
|
||||||
destbufsize = to!uint(buf.length) * 2;
|
destbufsize = to!uint(buf.length) * 2;
|
||||||
auto destbuf = new ubyte[destbufsize];
|
auto destbuf = uninitializedArray!(ubyte[])(destbufsize);
|
||||||
size_t destFill;
|
size_t destFill;
|
||||||
|
|
||||||
zs.next_in = cast(ubyte*) buf.ptr;
|
zs.next_in = cast(ubyte*) buf.ptr;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue