File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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:
142142private :
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
147157unittest
You can’t perform that action at this time.
0 commit comments