@@ -96,8 +96,8 @@ class ByteBuffer {
9696
9797 // Attribute for the number of elements in the buffer (a const)
9898 // - `num_elements_` is a const and passed during construction of both read-only and write buffers.
99- // - It indicates the expected number of elements in the buffer payload declared upfront .
100- // - This is treated as an invariant, so if the payload count mismatches, exceptions are thrown.
99+ // - It indicates the expected number of elements in the buffer payload.
100+ // - This is treated as an invariant. If the actual payload count mismatches, exceptions are thrown.
101101 const size_t num_elements_;
102102
103103 // Variables for element span iterator.
@@ -155,7 +155,7 @@ ByteBuffer<Codec>::ByteBuffer(
155155 Codec codec)
156156 : elements_span_(elements_span),
157157 elements_span_size_ (elements_span.size()),
158- // `num_elements_` is the expected number of elements in the buffer declared upfront .
158+ // `num_elements_` is the expected number of elements in the buffer.
159159 // - if the actual payload count mismatches, exceptions are thrown.
160160 num_elements_(num_elements),
161161 codec_(std::move(codec)),
@@ -206,15 +206,12 @@ inline void ByteBuffer<Codec>::InitializeFromSpan() const {
206206 // Fixed-size layout has implicit offsets from index * element_size.
207207 // We validate shape and derive element count. No need to store offsets.
208208 if constexpr (is_fixed_sized) {
209- if (element_size_ <= 0 ) {
210- throw InvalidInputException (" Invalid fixed-size buffer: element_size must be greater than zero" );
211- }
212209 if ((readable_size % element_size_) != 0 ) {
213210 throw InvalidInputException (" Malformed fixed-size buffer: buffer does not align with element_size" );
214211 }
215212
216213 // Check if the num_elements passed at contruction time coincides with the calculated from the payload size.
217- // This is a division of integer values, however it results in a correct integer result because of the modulo guard above.
214+ // Although this is a division of integers, the result is an integer (no remainder) because of the modulo guard above.
218215 const size_t num_elements_on_payload = readable_size / element_size_;
219216 if (num_elements_on_payload != num_elements_) {
220217 throw InvalidInputException (" Malformed fixed-size buffer: num_elements on payload != num_elements_ expected." );
@@ -454,10 +451,6 @@ template <class Codec>
454451inline void ByteBuffer<Codec>::InitializeForWriteBuffer(size_t variable_size_reserved_bytes_hint) {
455452 // Fixed-size elements
456453 if constexpr (is_fixed_sized) {
457- if (element_size_ <= 0 ) {
458- throw InvalidInputException (" Invalid fixed-size buffer: element_size must be greater than zero" );
459- }
460-
461454 // write_buffer can be allocated to precise size since the element size and number of elements are known.
462455 // We initialize it to 0s to have random-ish access during writes.
463456 const size_t fixed_size_total_bytes = prefix_size_ + (num_elements_ * element_size_);
0 commit comments