From f1672b6c7816f2d35eb82d174a91a6858bd4176c Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Mon, 5 Feb 2024 21:52:03 +0100 Subject: [PATCH] feat(ricepp): some minor speed improvements --- ricepp/include/ricepp/detail/decode.h | 8 ++++---- ricepp/include/ricepp/detail/encode.h | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ricepp/include/ricepp/detail/decode.h b/ricepp/include/ricepp/detail/decode.h index 0a6dfee2..5225c4e7 100644 --- a/ricepp/include/ricepp/detail/decode.h +++ b/ricepp/include/ricepp/detail/decode.h @@ -50,20 +50,20 @@ void decode_block(V block, BitstreamReader& reader, PixelTraits const& traits, if (fsp1 == 0) [[unlikely]] { std::fill(block.begin(), block.end(), traits.write(last)); } else if (fsp1 > kFsMax) [[unlikely]] { - for (size_t i = 0; i < block.size(); ++i) { - block[i] = reader.template read_bits(kPixelBits); + for (auto& b : block) { + b = reader.template read_bits(kPixelBits); } last = traits.read(block.back()); } else { auto const fs = fsp1 - 1; - for (size_t i = 0; i < block.size(); ++i) { + for (auto& b : block) { pixel_value_type diff = reader.find_first_set() << fs; if (fs > 0) { diff |= reader.template read_bits(fs); } last += static_cast>( (diff & 1) ? ~(diff >> 1) : (diff >> 1)); - block[i] = traits.write(last); + b = traits.write(last); } } diff --git a/ricepp/include/ricepp/detail/encode.h b/ricepp/include/ricepp/detail/encode.h index 19e249d7..98412cfb 100644 --- a/ricepp/include/ricepp/detail/encode.h +++ b/ricepp/include/ricepp/detail/encode.h @@ -125,8 +125,8 @@ void encode_block(V block, BitstreamWriter& writer, PixelTraits const& traits, // the input pixel data. This is really unlikely, so reading the input // pixels again is fine. writer.write_bits(kFsMax + 1, kFsBits); - for (size_t i = 0; i < block.size(); ++i) { - writer.write_bits(block[i], kPixelBits); + for (auto& b : block) { + writer.write_bits(b, kPixelBits); } } else { // Encode the difference values using Rice entropy coding. @@ -134,7 +134,7 @@ void encode_block(V block, BitstreamWriter& writer, PixelTraits const& traits, for (size_t i = 0; i < block.size(); ++i) { pixel_value_type const diff = delta[i]; pixel_value_type const top = diff >> fs; - if (top > 0) { + if (top > 0) [[unlikely]] { writer.write_bit(0, top); } writer.write_bit(1);