diff options
author | Bastien Bouclet | 2019-04-08 19:23:31 +0200 |
---|---|---|
committer | Filippos Karapetis | 2019-04-13 16:24:25 +0300 |
commit | ae9eeb731f435d16f2bb9ae69d48ce60c3a47fa3 (patch) | |
tree | f9d0ad64b05a656f18a978517ffdcddd1ed6874c /test/common | |
parent | 2af325f60adce92528405cee61c3f4aca447c292 (diff) | |
download | scummvm-rg350-ae9eeb731f435d16f2bb9ae69d48ce60c3a47fa3.tar.gz scummvm-rg350-ae9eeb731f435d16f2bb9ae69d48ce60c3a47fa3.tar.bz2 scummvm-rg350-ae9eeb731f435d16f2bb9ae69d48ce60c3a47fa3.zip |
COMMON: Rework the BitStream class to improve its performance
* Fixed peekBits not to seek the underlying stream. Seeking can be slow
when the stream is a file.
* Changed multi-bit operations to work on multiple bits at once rather
than iterating over single-bit operations.
This is an almost direct port of a patch for xoreos provided by DrMcCoy.
Diffstat (limited to 'test/common')
-rw-r--r-- | test/common/bitstream.h | 50 |
1 files changed, 47 insertions, 3 deletions
diff --git a/test/common/bitstream.h b/test/common/bitstream.h index 0488169183..742f0c18b1 100644 --- a/test/common/bitstream.h +++ b/test/common/bitstream.h @@ -50,7 +50,7 @@ public: private: template<class MS, class BS> void tmpl_skip() { - byte contents[] = { 'a', 'b' }; + byte contents[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' }; MS ms(contents, sizeof(contents)); @@ -61,6 +61,8 @@ private: bs.skip(4); TS_ASSERT_EQUALS(bs.pos(), 9u); TS_ASSERT_EQUALS(bs.getBits(3), 6u); + bs.skip(65); + TS_ASSERT_EQUALS(bs.pos(), 77u); TS_ASSERT(!bs.eos()); } public: @@ -133,7 +135,7 @@ private: TS_ASSERT_EQUALS(bs.pos(), 3u); bs.skip(8); TS_ASSERT_EQUALS(bs.pos(), 11u); - TS_ASSERT_EQUALS(bs.peekBits(5), 2u); + TS_ASSERT_EQUALS(bs.peekBits(6), 4u); TS_ASSERT(!bs.eos()); } public: @@ -203,7 +205,7 @@ private: TS_ASSERT_EQUALS(bs.pos(), 3u); bs.skip(8); TS_ASSERT_EQUALS(bs.pos(), 11u); - TS_ASSERT_EQUALS(bs.peekBits(5), 12u); + TS_ASSERT_EQUALS(bs.peekBits(20), 12u); TS_ASSERT(!bs.eos()); } public: @@ -211,4 +213,46 @@ public: tmpl_peek_bits_lsb<Common::MemoryReadStream, Common::BitStream8LSB>(); tmpl_peek_bits_lsb<Common::BitStreamMemoryStream, Common::BitStreamMemory8LSB>(); } + +private: + template<class MS, class BS> + void tmpl_align() { + byte contents[] = { 'a', 'b' }; + + MS ms(contents, sizeof(contents)); + + BS bs(ms); + TS_ASSERT_EQUALS(bs.pos(), 0u); + bs.align(); + TS_ASSERT_EQUALS(bs.pos(), 0u); + bs.skip(3); + bs.align(); + TS_ASSERT_EQUALS(bs.pos(), 8u); + } +public: + void test_align() { + tmpl_align<Common::MemoryReadStream, Common::BitStream8LSB>(); + tmpl_align<Common::BitStreamMemoryStream, Common::BitStreamMemory8LSB>(); + } + +private: + template<class MS, class BS> + void tmpl_align_16() { + byte contents[] = { 'a', 'b' }; + + MS ms(contents, sizeof(contents)); + + BS bs(ms); + TS_ASSERT_EQUALS(bs.pos(), 0u); + bs.align(); + TS_ASSERT_EQUALS(bs.pos(), 0u); + bs.skip(3); + bs.align(); + TS_ASSERT_EQUALS(bs.pos(), 16u); + } +public: + void test_align_16() { + tmpl_align_16<Common::MemoryReadStream, Common::BitStream16BELSB>(); + tmpl_align_16<Common::BitStreamMemoryStream, Common::BitStreamMemory16BELSB>(); + } }; |