@@ -40,14 +40,11 @@ namespace bitstream
4040 if constexpr (sizeof (T) > 4 )
4141 {
4242 // If the given range is bigger than a word (32 bits)
43- int max_words = (num_bits - 1 ) / 32 + 1 ;
44- for (int i = 0 ; i < max_words; i++)
45- {
46- int shift = i * 32 ;
47- int bit_count = (std::min)(num_bits - shift, 32 );
48- uint32_t unsigned_value = static_cast <uint32_t >((value - min) >> shift);
49- BS_ASSERT (writer.serialize_bits (unsigned_value, bit_count));
50- }
43+ uint32_t unsigned_value = static_cast <uint32_t >(value - min);
44+ BS_ASSERT (writer.serialize_bits (unsigned_value, 32 ));
45+
46+ unsigned_value = static_cast <uint32_t >((value - min) >> 32 );
47+ BS_ASSERT (writer.serialize_bits (unsigned_value, num_bits - 32 ));
5148 }
5249 else
5350 {
@@ -69,19 +66,15 @@ namespace bitstream
6966
7067 if constexpr (sizeof (T) > 4 )
7168 {
69+ // If the given range is bigger than a word (32 bits)
7270 value = 0 ;
71+ uint32_t unsigned_value;
7372
74- // If the given range is bigger than a word (32 bits)
75- int max_words = (num_bits - 1 ) / 32 + 1 ;
76- for (int i = 0 ; i < max_words; i++)
77- {
78- uint32_t unsigned_value;
79- int shift = i * 32 ;
80- int bit_count = (std::min)(num_bits - shift, 32 );
81- BS_ASSERT (reader.serialize_bits (unsigned_value, bit_count));
73+ BS_ASSERT (reader.serialize_bits (unsigned_value, 32 ));
74+ value |= static_cast <T>(unsigned_value);
8275
83- value |= static_cast <T>( unsigned_value) << shift ;
84- }
76+ BS_ASSERT (reader. serialize_bits ( unsigned_value, num_bits - 32 )) ;
77+ value |= static_cast <T>(unsigned_value) << 32 ;
8578
8679 value += min;
8780 }
@@ -124,14 +117,11 @@ namespace bitstream
124117 if constexpr (sizeof (T) > 4 && num_bits > 32 )
125118 {
126119 // If the given range is bigger than a word (32 bits)
127- int max_words = (num_bits - 1 ) / 32 + 1 ;
128- for (int i = 0 ; i < max_words; i++)
129- {
130- int shift = i * 32 ;
131- int bit_count = (std::min)(num_bits - shift, 32 );
132- uint32_t unsigned_value = static_cast <uint32_t >((value - Min) >> shift);
133- BS_ASSERT (writer.serialize_bits (unsigned_value, bit_count));
134- }
120+ uint32_t unsigned_value = static_cast <uint32_t >(value - Min);
121+ BS_ASSERT (writer.serialize_bits (unsigned_value, 32 ));
122+
123+ unsigned_value = static_cast <uint32_t >((value - Min) >> 32 );
124+ BS_ASSERT (writer.serialize_bits (unsigned_value, num_bits - 32 ));
135125 }
136126 else
137127 {
@@ -153,19 +143,15 @@ namespace bitstream
153143
154144 if constexpr (sizeof (T) > 4 && num_bits > 32 )
155145 {
146+ // If the given range is bigger than a word (32 bits)
156147 value = 0 ;
148+ uint32_t unsigned_value;
157149
158- // If the given range is bigger than a word (32 bits)
159- int max_words = (num_bits - 1 ) / 32 + 1 ;
160- for (int i = 0 ; i < max_words; i++)
161- {
162- uint32_t unsigned_value;
163- int shift = i * 32 ;
164- int bit_count = (std::min)(num_bits - shift, 32 );
165- BS_ASSERT (reader.serialize_bits (unsigned_value, bit_count));
166-
167- value |= static_cast <T>(unsigned_value) << shift;
168- }
150+ BS_ASSERT (reader.serialize_bits (unsigned_value, 32 ));
151+ value |= static_cast <T>(unsigned_value);
152+
153+ BS_ASSERT (reader.serialize_bits (unsigned_value, num_bits - 32 ));
154+ value |= static_cast <T>(unsigned_value) << 32 ;
169155
170156 value += Min;
171157 }
0 commit comments