BLI: refactor IndexMask for better performance and memory usage #104629
|
@ -278,7 +278,7 @@ template<typename T> Vector<IndexRange> split_by_chunk(Span<T> indices);
|
|||
template<typename T>
|
||||
int64_t split_to_ranges_and_spans(Span<T> indices,
|
||||
int64_t range_threshold,
|
||||
Vector<std::variant<IndexRange, Span<T>>> &r_parts);
|
||||
Vector<std::variant<IndexRange, Span<T>>> &r_segments);
|
||||
template<typename T> bool non_empty_is_range(const Span<T> indices);
|
||||
template<typename T> IndexRange non_empty_as_range(const Span<T> indices);
|
||||
template<typename T> int64_t find_size_of_next_range(const Span<T> indices);
|
||||
|
|
|
@ -182,21 +182,21 @@ template<typename T> Vector<IndexRange> split_by_chunk(const Span<T> indices)
|
|||
template<typename T>
|
||||
int64_t split_to_ranges_and_spans(const Span<T> indices,
|
||||
const int64_t range_threshold,
|
||||
Vector<std::variant<IndexRange, Span<T>>> &r_parts)
|
||||
Vector<std::variant<IndexRange, Span<T>>> &r_segments)
|
||||
{
|
||||
BLI_assert(range_threshold >= 1);
|
||||
const int64_t old_parts_num = r_parts.size();
|
||||
const int64_t old_segments_num = r_segments.size();
|
||||
Span<T> remaining_indices = indices;
|
||||
while (!remaining_indices.is_empty()) {
|
||||
if (non_empty_is_range(remaining_indices)) {
|
||||
/* All remaining indices are range. */
|
||||
r_parts.append(non_empty_as_range(remaining_indices));
|
||||
r_segments.append(non_empty_as_range(remaining_indices));
|
||||
break;
|
||||
}
|
||||
if (non_empty_is_range(remaining_indices.take_front(range_threshold))) {
|
||||
/* Next segment is a range. Now find the place where the range ends. */
|
||||
const int64_t segment_size = find_size_of_next_range(remaining_indices);
|
||||
r_parts.append(IndexRange(remaining_indices[0], segment_size));
|
||||
r_segments.append(IndexRange(remaining_indices[0], segment_size));
|
||||
remaining_indices = remaining_indices.drop_front(segment_size);
|
||||
continue;
|
||||
}
|
||||
|
@ -204,14 +204,14 @@ int64_t split_to_ranges_and_spans(const Span<T> indices,
|
|||
const int64_t segment_size = find_size_until_next_range(remaining_indices, range_threshold);
|
||||
const Span<T> segment_indices = remaining_indices.take_front(segment_size);
|
||||
if (non_empty_is_range(segment_indices)) {
|
||||
r_parts.append(non_empty_as_range(segment_indices));
|
||||
r_segments.append(non_empty_as_range(segment_indices));
|
||||
}
|
||||
else {
|
||||
r_parts.append(segment_indices);
|
||||
r_segments.append(segment_indices);
|
||||
}
|
||||
remaining_indices = remaining_indices.drop_front(segment_size);
|
||||
}
|
||||
return r_parts.size() - old_parts_num;
|
||||
return r_segments.size() - old_segments_num;
|
||||
}
|
||||
|
||||
template<typename T> IndexMask to_index_mask(const Span<T> indices, IndexMaskMemory &memory)
|
||||
|
|
Loading…
Reference in New Issue