Skip to content

Commit

Permalink
bulk copy decomprssed data
Browse files Browse the repository at this point in the history
Change-Id: Ie5ff9ebaffe3eff70e12fd52b608fc90468e650a
  • Loading branch information
garymm authored and oliverlee committed Jan 6, 2024
1 parent b4f1ad9 commit f2be076
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/decompress.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "huffman/huffman.hpp"

#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <expected>
Expand Down Expand Up @@ -70,11 +69,13 @@ auto decompress(
compressed_bits.size(), std::size_t{len} * CHAR_BIT) and
"not enough bits");

// TODO: this is probably really slow because back_inserter means we can
// only copy a single byte at a time. We should look into options for bulk
// copying.
std::copy_n(
compressed_bits.byte_data(), len, std::back_inserter(decompressed));
// Using vector::insert instead of std::copy to allow for bulk copying.
decompressed.insert(
decompressed.end(),
compressed_bits.byte_data(),
compressed_bits
.byte_data() + // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
len);
compressed_bits.consume(CHAR_BIT * len);
} else {
// TODO: implement
Expand Down

0 comments on commit f2be076

Please sign in to comment.