Inlined BitBuffer.getBytes() into its single usage (with simplification because the bit length is a multiple of 8) in most language versions, synchronized comment and variable name in Rust version.

This commit is contained in:
Project Nayuki
2018-10-06 04:44:03 +00:00
parent 8c262c00dd
commit c7bc281e18
9 changed files with 40 additions and 69 deletions
-8
View File
@@ -31,14 +31,6 @@ BitBuffer::BitBuffer()
: std::vector<bool>() {}
std::vector<std::uint8_t> BitBuffer::getBytes() const {
std::vector<std::uint8_t> result(size() / 8 + (size() % 8 == 0 ? 0 : 1));
for (std::size_t i = 0; i < size(); i++)
result[i >> 3] |= (*this)[i] ? 1 << (7 - (i & 7)) : 0;
return result;
}
void BitBuffer::appendBits(std::uint32_t val, int len) {
if (len < 0 || len > 31 || val >> len != 0)
throw std::domain_error("Value out of range");