BLI: Improve IndexMask::complement() performance #108331

Merged
Hans Goudey merged 15 commits from HooglyBoogly/blender:index-mask-complement-performance into main 2023-05-31 17:11:11 +02:00
1 changed files with 12 additions and 1 deletions
Showing only changes of commit 64d31f1b65 - Show all commits

View File

@ -334,6 +334,17 @@ static void range_to_segments(const IndexRange range, Vector<IndexMaskSegment, 1
}
}
static int64_t get_size_before_gap(const Span<int16_t> indices)
{
BLI_assert(indices.size() >= 2);
if (indices[1] > indices[0] + 1) {
HooglyBoogly marked this conversation as resolved Outdated

r_segments

`r_segments`
/* For sparse indices, often the next gap is just after the next index.
* In this case we can skip the logarithmic check below.*/
return 1;
}
return unique_sorted_indices::find_size_of_next_range(indices);
}
static void inverted_indices_to_segments(const IndexMaskSegment segment,
LinearAllocator<> &allocator,
Vector<IndexMaskSegment, 16> &r_segments)
@ -362,7 +373,7 @@ static void inverted_indices_to_segments(const IndexMaskSegment segment,
Span<int16_t> indices = segment.base_span();
while (indices.size() > 1) {
const int64_t size_before_gap = unique_sorted_indices::find_size_of_next_range(indices);
const int64_t size_before_gap = get_size_before_gap(indices);
if (size_before_gap == indices.size()) {
break;
HooglyBoogly marked this conversation as resolved
Review

Add indices "at once" instead of one by one. Essentially increasing inverted_indices_count only once.

Add indices "at once" instead of one by one. Essentially increasing ` inverted_indices_count` only once.
Review

This didn't seem to change the performance, but I did it anyway just in case, it is a bit clearer

This didn't seem to change the performance, but I did it anyway just in case, it is a bit clearer
}