(
rows: &mut [&[u8]],
options: SortOptions,
validate_utf8: bool,
)
| 310 | } |
| 311 | |
| 312 | fn decode_binary_view_inner( |
| 313 | rows: &mut [&[u8]], |
| 314 | options: SortOptions, |
| 315 | validate_utf8: bool, |
| 316 | ) -> BinaryViewArray { |
| 317 | let len = rows.len(); |
| 318 | let inline_str_max_len = MAX_INLINE_VIEW_LEN as usize; |
| 319 | |
| 320 | let mut null_count = 0; |
| 321 | |
| 322 | let nulls = MutableBuffer::collect_bool(len, |x| { |
| 323 | let valid = rows[x][0] != null_sentinel(options); |
| 324 | null_count += !valid as usize; |
| 325 | valid |
| 326 | }); |
| 327 | |
| 328 | // If we are validating UTF-8, decode all string values (including short strings) |
| 329 | // into the values buffer and validate UTF-8 once. If not validating, |
| 330 | // we save memory by only copying long strings to the values buffer, as short strings |
| 331 | // will be inlined into the view and do not need to be stored redundantly. |
| 332 | let values_capacity = if validate_utf8 { |
| 333 | // Capacity for all long and short strings |
| 334 | rows.iter().map(|row| decoded_len(row, options)).sum() |
| 335 | } else { |
| 336 | // Capacity for all long strings plus room for one short string |
| 337 | rows.iter().fold(0, |acc, row| { |
| 338 | let len = decoded_len(row, options); |
| 339 | if len > inline_str_max_len { |
| 340 | acc + len |
| 341 | } else { |
| 342 | acc |
| 343 | } |
| 344 | }) + inline_str_max_len |
| 345 | }; |
| 346 | let mut values = MutableBuffer::new(values_capacity); |
| 347 | |
| 348 | let mut views = BufferBuilder::<u128>::new(len); |
| 349 | for row in rows { |
| 350 | let start_offset = values.len(); |
| 351 | let offset = decode_blocks(row, options, |b| values.extend_from_slice(b)); |
| 352 | // Measure string length via change in values buffer. |
| 353 | // Used to check if decoded value should be truncated (short string) when validate_utf8 is false |
| 354 | let decoded_len = values.len() - start_offset; |
| 355 | if row[0] == null_sentinel(options) { |
| 356 | debug_assert_eq!(offset, 1); |
| 357 | debug_assert_eq!(start_offset, values.len()); |
| 358 | views.append(0); |
| 359 | } else { |
| 360 | // Safety: we just appended the data to the end of the buffer |
| 361 | let val = unsafe { values.get_unchecked_mut(start_offset..) }; |
| 362 | |
| 363 | if options.descending { |
| 364 | val.iter_mut().for_each(|o| *o = !*o); |
| 365 | } |
| 366 | |
| 367 | let view = make_view(val, 0, start_offset as u32); |
| 368 | views.append(view); |
| 369 |
no test coverage detected