From 9f835f898c45670251836cc9219f632429cc4871 Mon Sep 17 00:00:00 2001 From: Steven Schveighoffer Date: Wed, 8 Mar 2023 13:56:56 -0500 Subject: [PATCH] Used max instead of min by accident. Fix unittest to pass on Apple M1 --- source/iopipe/buffer.d | 22 ++++++++++++---------- source/iopipe/textpipe.d | 4 ++-- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/source/iopipe/buffer.d b/source/iopipe/buffer.d index be32bea..602adb1 100644 --- a/source/iopipe/buffer.d +++ b/source/iopipe/buffer.d @@ -547,28 +547,30 @@ private: { RingBuffer!(ubyte, 8192) buf; assert(buf.extend(4096) == 4096); - assert(buf.avail == 8192 - 4096); - assert(buf.capacity == 8192); + // some systems do not have a page size of 4k + auto cap = buf.capacity; + assert(cap >= 8192); + assert(buf.avail == cap - 4096); buf.window[0] = 0; - assert(buf.buffer.length == 8192 * 2); + assert(buf.buffer.length == cap * 2); assert(buf.extend(4096) == 4096); - assert(buf.avail == 0); - assert(buf.capacity == 8192); + assert(buf.avail == cap - 8192); + assert(buf.capacity == cap); buf.releaseFront(4096); - assert(buf.avail == 4096); - assert(buf.capacity == 8192); + assert(buf.avail == cap - 4096); + assert(buf.capacity == cap); assert(buf.extend(4096) == 4096); - assert(buf.avail == 0); - assert(buf.capacity == 8192); + assert(buf.avail == cap - 8192); + assert(buf.capacity == cap); import std.algorithm : copy, map, equal; import std.range : iota; iota(8192).map!(a => cast(ubyte)a).copy(buf.window); assert(equal(iota(8192).map!(a => cast(ubyte)a), buf.window)); buf.releaseFront(4096); assert(equal(iota(4096, 8192).map!(a => cast(ubyte)a), buf.window)); - assert(buf.released == 0); // assure we wrap around + assert(buf.released <= cap); // assure we wrap around assert(buf.extend(8192) == 8192); assert(equal(iota(4096, 8192).map!(a => cast(ubyte)a), buf.window[0 .. 4096])); } diff --git a/source/iopipe/textpipe.d b/source/iopipe/textpipe.d index 1fa1ada..368fa91 100644 --- a/source/iopipe/textpipe.d +++ b/source/iopipe/textpipe.d @@ -934,14 +934,14 @@ template textConverter(bool ensureBOM = false, Chain) static if(is(Unqual!Char == Unqual!SrcChar)) { import std.algorithm.mutation: copy; - import std.algorithm.comparison: max; + import std.algorithm.comparison: min; // try an extend when window length gets to be less than read size. if(chain.window.length < buf.length) chain.extend(buf.length - chain.window.length); if(chain.window.length == 0) // no more data return 0; - immutable len = max(chain.window.length, buf.length); + immutable len = min(chain.window.length, buf.length); copy(chain.window[0 .. len], buf[0 .. len]); chain.release(len); return result + len;