Skip to content

Commit d8172de

Browse files
Fix bitarray unittest on Win32
1 parent 6241efb commit d8172de

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

src/dmd/root/bitarray.d

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ nothrow:
5050
if (!len)
5151
length(b.len);
5252
assert(len == b.len);
53-
memcpy(ptr, b.ptr, (len + BitsPerChunk - 1) / 8);
53+
memcpy(ptr, b.ptr, bytes(len));
5454
}
5555

5656
bool opIndex(size_t idx) const pure nothrow @nogc
@@ -74,12 +74,12 @@ nothrow:
7474

7575
bool opEquals(const ref BitArray b) const
7676
{
77-
return len == b.len && memcmp(ptr, b.ptr, (len + BitsPerChunk - 1) / 8) == 0;
77+
return len == b.len && memcmp(ptr, b.ptr, bytes(len)) == 0;
7878
}
7979

8080
void zero()
8181
{
82-
memset(ptr, 0, (len + BitsPerChunk - 1) / 8);
82+
memset(ptr, 0, bytes(len));
8383
}
8484

8585
/******
@@ -142,6 +142,16 @@ nothrow:
142142
private:
143143
size_t len; // length in bits
144144
size_t *ptr;
145+
146+
static size_t chunks(const size_t len) @nogc nothrow pure @safe
147+
{
148+
return (len + BitsPerChunk - 1) / BitsPerChunk;
149+
}
150+
151+
static size_t bytes(const size_t len) @nogc nothrow pure @safe
152+
{
153+
return chunks(len) * ChunkSize;
154+
}
145155
}
146156

147157
unittest

0 commit comments

Comments
 (0)