Merge pull request #49 from MartinNowak/buffer_init

avoid Buffer type which creates a huge __initZ symbol
This commit is contained in:
Sönke Ludwig 2018-01-16 10:24:23 +01:00 committed by GitHub
commit eb82c2ad35
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 8 deletions

View file

@ -658,10 +658,10 @@ mixin(tracer);
if (isInputStream!InputStream) if (isInputStream!InputStream)
{ {
import std.algorithm.comparison : min; import std.algorithm.comparison : min;
import vibe.internal.allocator : theAllocator, makeArray, dispose;
static struct Buffer { ubyte[64*1024 - 4*size_t.sizeof] bytes = void; } scope buffer = () @trusted { return cast(ubyte[]) theAllocator.allocate(64*1024); }();
scope bufferobj = new Buffer; // FIXME: use heap allocation scope (exit) () @trusted { theAllocator.dispose(buffer); }();
auto buffer = bufferobj.bytes[];
//logTrace("default write %d bytes, empty=%s", nbytes, stream.empty); //logTrace("default write %d bytes, empty=%s", nbytes, stream.empty);
if( nbytes == 0 ){ if( nbytes == 0 ){

View file

@ -39,12 +39,10 @@ ulong pipe(InputStream, OutputStream)(InputStream source, OutputStream sink, ulo
@blocking @trusted @blocking @trusted
if (isOutputStream!OutputStream && isInputStream!InputStream) if (isOutputStream!OutputStream && isInputStream!InputStream)
{ {
import vibe.internal.allocator : theAllocator, make, dispose; import vibe.internal.allocator : theAllocator, makeArray, dispose;
static struct Buffer { ubyte[64*1024] bytes = void; } scope buffer = cast(ubyte[]) theAllocator.allocate(64*1024);
auto bufferobj = theAllocator.make!Buffer(); scope (exit) theAllocator.dispose(buffer);
scope (exit) theAllocator.dispose(bufferobj);
auto buffer = bufferobj.bytes;
//logTrace("default write %d bytes, empty=%s", nbytes, stream.empty); //logTrace("default write %d bytes, empty=%s", nbytes, stream.empty);
ulong ret = 0; ulong ret = 0;