BLI: refactor IndexMask for better performance and memory usage #104629
|
@ -165,7 +165,7 @@ inline const std::array<int16_t, max_chunk_size> &get_static_indices_array()
|
|||
return data;
|
||||
}
|
||||
|
||||
inline int64_t index_to_chunk_index(const int64_t i)
|
||||
inline int64_t index_to_chunk_id(const int64_t i)
|
||||
{
|
||||
return i >> chunk_size_shift;
|
||||
}
|
||||
|
@ -253,14 +253,14 @@ inline IndexMask::IndexMask(const IndexRange range)
|
|||
}
|
||||
*this = get_static_index_mask_for_min_size(range.one_after_last());
|
||||
|
||||
const int64_t first_chunk_i = index_to_chunk_index(range.first());
|
||||
const int64_t last_chunk_i = index_to_chunk_index(range.last());
|
||||
const int64_t first_chunk_id = index_to_chunk_id(range.first());
|
||||
const int64_t last_chunk_id = index_to_chunk_id(range.last());
|
||||
|
||||
data_.chunks_num = last_chunk_i - first_chunk_i + 1;
|
||||
data_.chunks_num = last_chunk_id - first_chunk_id + 1;
|
||||
data_.indices_num = range.size();
|
||||
data_.chunks -= first_chunk_i;
|
||||
data_.chunk_offsets -= first_chunk_i;
|
||||
data_.chunk_sizes_cumulative -= first_chunk_i;
|
||||
data_.chunks -= first_chunk_id;
|
||||
data_.chunk_offsets -= first_chunk_id;
|
||||
data_.chunk_sizes_cumulative -= first_chunk_id;
|
||||
data_.begin_it.segment_index = 0;
|
||||
data_.begin_it.index_in_segment = range.first() & chunk_mask_low;
|
||||
data_.end_it.segment_index = 0;
|
||||
|
|
|
@ -102,13 +102,13 @@ static void split_by_chunk_recursive(const Span<T> indices,
|
|||
}
|
||||
const T first_index = indices.first();
|
||||
const T last_index = indices.last();
|
||||
const int64_t first_chunk_index = index_to_chunk_index(first_index);
|
||||
const int64_t last_chunk_index = index_to_chunk_index(last_index);
|
||||
if (first_chunk_index == last_chunk_index) {
|
||||
const int64_t first_chunk_id = index_to_chunk_id(first_index);
|
||||
const int64_t last_chunk_id = index_to_chunk_id(last_index);
|
||||
if (first_chunk_id == last_chunk_id) {
|
||||
r_chunks.append_as(offset, indices.size());
|
||||
return;
|
||||
}
|
||||
const int64_t middle_chunk_index = (first_chunk_index + last_chunk_index + 1) / 2;
|
||||
const int64_t middle_chunk_index = (first_chunk_id + last_chunk_id + 1) / 2;
|
||||
const int64_t split_value = middle_chunk_index * max_chunk_size - 1;
|
||||
const int64_t left_split_size = std::upper_bound(indices.begin(), indices.end(), split_value) -
|
||||
indices.begin();
|
||||
|
@ -185,10 +185,10 @@ template<typename T> IndexMask to_index_mask(const Span<T> indices, ResourceScop
|
|||
const Span<T> indices_in_chunk = indices.slice(range_for_chunk);
|
||||
BLI_assert(!indices_in_chunk.is_empty());
|
||||
|
||||
const int64_t chunk_i = index_to_chunk_index(int64_t(indices_in_chunk[0]));
|
||||
BLI_assert(chunk_i == index_to_chunk_index(int64_t(indices_in_chunk.last())));
|
||||
const int64_t chunk_id = index_to_chunk_id(int64_t(indices_in_chunk[0]));
|
||||
BLI_assert(chunk_id == index_to_chunk_id(int64_t(indices_in_chunk.last())));
|
||||
Chunk &chunk = chunks[i];
|
||||
const int64_t chunk_offset = max_chunk_size * chunk_i;
|
||||
const int64_t chunk_offset = max_chunk_size * chunk_id;
|
||||
chunk_offsets[i] = chunk_offset;
|
||||
|
||||
if (indices_in_chunk.size() == max_chunk_size) {
|
||||
|
|
Loading…
Reference in New Issue