MCPcopy Create free account
hub / github.com/apache/arrow / GetAligned

Method GetAligned

cpp/src/arrow/util/bit_stream_utils_internal.h:298–326  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

296
297template <typename T>
298inline bool BitReader::GetAligned(int num_bytes, T* v) {
299 if (ARROW_PREDICT_FALSE(num_bytes > static_cast<int>(sizeof(T)))) {
300 return false;
301 }
302
303 int bytes_read = static_cast<int>(bit_util::BytesForBits(bit_offset_));
304 if (ARROW_PREDICT_FALSE(byte_offset_ + bytes_read + num_bytes > max_bytes_)) {
305 return false;
306 }
307
308 // Advance byte_offset to next unread byte and read num_bytes
309 byte_offset_ += bytes_read;
310 if constexpr (std::is_same_v<T, bool>) {
311 // ARROW-18031: if we're trying to get an aligned bool, just check
312 // the LSB of the next byte and move on. If we memcpy + FromLittleEndian
313 // as usual, we have potential undefined behavior for bools if the value
314 // isn't 0 or 1
315 *v = *(buffer_ + byte_offset_) & 1;
316 } else {
317 memcpy(v, buffer_ + byte_offset_, num_bytes);
318 *v = arrow::bit_util::FromLittleEndian(*v);
319 }
320 byte_offset_ += num_bytes;
321
322 bit_offset_ = 0;
323 buffered_values_ =
324 detail::ReadLittleEndianWord(buffer_ + byte_offset_, max_bytes_ - byte_offset_);
325 return true;
326}
327
328inline bool BitReader::Advance(int64_t num_bits) {
329 int64_t bits_required = bit_offset_ + num_bits;

Callers

nothing calls this directly

Calls 3

BytesForBitsFunction · 0.85
ReadLittleEndianWordFunction · 0.85
FromLittleEndianFunction · 0.70

Tested by

no test coverage detected