Skip to content

Commit 73425fd

Browse files
committed
refactor(cyclic_hash): use fast types internally
1 parent 04bb7e8 commit 73425fd

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

include/dwarfs/writer/internal/cyclic_hash.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,21 @@ class rsync_hash {
3737
rsync_hash() = default;
3838

3939
DWARFS_FORCE_INLINE value_type operator()() const {
40-
return a_ | (static_cast<value_type>(b_) << 16);
40+
return (a_ & 0xffff) | (static_cast<value_type>(b_ & 0xffff) << 16);
4141
}
4242

4343
DWARFS_FORCE_INLINE void set(value_type hash) {
44-
a_ = static_cast<uint16_t>(hash & 0xFFFF);
45-
b_ = static_cast<uint16_t>((hash >> 16) & 0xFFFF);
44+
a_ = hash & 0xFFFF;
45+
b_ = (hash >> 16) & 0xFFFF;
4646
}
4747

48-
DWARFS_FORCE_INLINE void update(uint8_t inbyte) {
48+
DWARFS_FORCE_INLINE void update(std::uint8_t inbyte) {
4949
a_ += inbyte;
5050
b_ += a_;
5151
++len_;
5252
}
5353

54-
DWARFS_FORCE_INLINE void update(uint8_t outbyte, uint8_t inbyte) {
54+
DWARFS_FORCE_INLINE void update(std::uint8_t outbyte, std::uint8_t inbyte) {
5555
a_ = a_ - outbyte + inbyte;
5656
b_ -= len_ * outbyte;
5757
b_ += a_;
@@ -64,17 +64,17 @@ class rsync_hash {
6464
}
6565

6666
static DWARFS_FORCE_INLINE constexpr value_type
67-
repeating_window(uint8_t byte, size_t length) {
68-
auto v = static_cast<uint16_t>(byte);
69-
auto a = static_cast<uint16_t>(v * length);
70-
auto b = static_cast<uint16_t>(v * (length * (length + 1)) / 2);
67+
repeating_window(std::uint8_t byte, size_t length) {
68+
auto v = static_cast<std::uint16_t>(byte);
69+
auto a = static_cast<std::uint16_t>(v * length);
70+
auto b = static_cast<std::uint16_t>(v * (length * (length + 1)) / 2);
7171
return static_cast<value_type>(a) | (static_cast<value_type>(b) << 16);
7272
}
7373

7474
private:
75-
uint16_t a_{0};
76-
uint16_t b_{0};
77-
int32_t len_{0};
75+
std::uint_fast16_t a_{0};
76+
std::uint_fast16_t b_{0};
77+
std::int_fast32_t len_{0};
7878
};
7979

8080
} // namespace dwarfs::writer::internal

0 commit comments

Comments
 (0)