Skip to content

Commit

Permalink
Merge pull request #37 from schveiguy/fixconvert
Browse files Browse the repository at this point in the history
Used max instead of min by accident. Fix unittest to pass on Apple M1
  • Loading branch information
schveiguy authored Mar 8, 2023
2 parents 6a8c10d + 9f835f8 commit 61141b6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
22 changes: 12 additions & 10 deletions source/iopipe/buffer.d
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
}
Expand Down
4 changes: 2 additions & 2 deletions source/iopipe/textpipe.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 61141b6

Please sign in to comment.