Cleanup: add const in various places
This commit is contained in:
parent
9dce2c9d14
commit
93da09d717
|
@ -42,56 +42,57 @@ namespace blender {
|
|||
* Those should eventually be de-duplicated with functions in BLI_math_base.h.
|
||||
* \{ */
|
||||
|
||||
inline constexpr int is_power_of_2_i_constexpr(int n)
|
||||
inline constexpr int is_power_of_2_i_constexpr(const int n)
|
||||
{
|
||||
return (n & (n - 1)) == 0;
|
||||
}
|
||||
|
||||
inline constexpr uint32_t log2_floor_u_constexpr(uint32_t x)
|
||||
inline constexpr uint32_t log2_floor_u_constexpr(const uint32_t x)
|
||||
{
|
||||
return x <= 1 ? 0 : 1 + log2_floor_u_constexpr(x >> 1);
|
||||
}
|
||||
|
||||
inline constexpr uint32_t log2_ceil_u_constexpr(uint32_t x)
|
||||
inline constexpr uint32_t log2_ceil_u_constexpr(const uint32_t x)
|
||||
{
|
||||
return (is_power_of_2_i_constexpr((int)x)) ? log2_floor_u_constexpr(x) :
|
||||
log2_floor_u_constexpr(x) + 1;
|
||||
}
|
||||
|
||||
inline constexpr uint32_t power_of_2_max_u_constexpr(uint32_t x)
|
||||
inline constexpr uint32_t power_of_2_max_u_constexpr(const uint32_t x)
|
||||
{
|
||||
return 1u << log2_ceil_u_constexpr(x);
|
||||
}
|
||||
|
||||
template<typename IntT> inline constexpr IntT ceil_division(IntT x, IntT y)
|
||||
template<typename IntT> inline constexpr IntT ceil_division(const IntT x, const IntT y)
|
||||
{
|
||||
BLI_STATIC_ASSERT(!std::is_signed<IntT>::value, "");
|
||||
return x / y + ((x % y) != 0);
|
||||
}
|
||||
|
||||
template<typename IntT> inline constexpr IntT floor_division(IntT x, IntT y)
|
||||
template<typename IntT> inline constexpr IntT floor_division(const IntT x, const IntT y)
|
||||
{
|
||||
BLI_STATIC_ASSERT(!std::is_signed<IntT>::value, "");
|
||||
return x / y;
|
||||
}
|
||||
|
||||
inline constexpr uint32_t ceil_division_by_fraction(uint32_t x,
|
||||
uint32_t numerator,
|
||||
uint32_t denominator)
|
||||
inline constexpr uint32_t ceil_division_by_fraction(const uint32_t x,
|
||||
const uint32_t numerator,
|
||||
const uint32_t denominator)
|
||||
{
|
||||
return (uint32_t)ceil_division((uint64_t)x * (uint64_t)denominator, (uint64_t)numerator);
|
||||
}
|
||||
|
||||
inline constexpr uint32_t floor_multiplication_with_fraction(uint32_t x,
|
||||
uint32_t numerator,
|
||||
uint32_t denominator)
|
||||
inline constexpr uint32_t floor_multiplication_with_fraction(const uint32_t x,
|
||||
const uint32_t numerator,
|
||||
const uint32_t denominator)
|
||||
{
|
||||
return (uint32_t)((uint64_t)x * (uint64_t)numerator / (uint64_t)denominator);
|
||||
}
|
||||
|
||||
inline constexpr uint32_t total_slot_amount_for_usable_slots(uint32_t min_usable_slots,
|
||||
uint32_t max_load_factor_numerator,
|
||||
uint32_t max_load_factor_denominator)
|
||||
inline constexpr uint32_t total_slot_amount_for_usable_slots(
|
||||
const uint32_t min_usable_slots,
|
||||
const uint32_t max_load_factor_numerator,
|
||||
const uint32_t max_load_factor_denominator)
|
||||
{
|
||||
return power_of_2_max_u_constexpr(ceil_division_by_fraction(
|
||||
min_usable_slots, max_load_factor_numerator, max_load_factor_denominator));
|
||||
|
@ -129,7 +130,7 @@ class LoadFactor {
|
|||
|
||||
uint32_t total_slots = this->compute_total_slots(min_usable_slots, numerator_, denominator_);
|
||||
total_slots = std::max(total_slots, min_total_slots);
|
||||
uint32_t usable_slots = floor_multiplication_with_fraction(
|
||||
const uint32_t usable_slots = floor_multiplication_with_fraction(
|
||||
total_slots, numerator_, denominator_);
|
||||
BLI_assert(min_usable_slots <= usable_slots);
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ template<typename Allocator = GuardedAllocator> class LinearAllocator : NonCopya
|
|||
*
|
||||
* The alignment has to be a power of 2.
|
||||
*/
|
||||
void *allocate(uint size, uint alignment)
|
||||
void *allocate(const uint size, const uint alignment)
|
||||
{
|
||||
BLI_assert(alignment >= 1);
|
||||
BLI_assert(is_power_of_2_i(alignment));
|
||||
|
@ -75,9 +75,10 @@ template<typename Allocator = GuardedAllocator> class LinearAllocator : NonCopya
|
|||
debug_allocated_amount_ += size;
|
||||
#endif
|
||||
|
||||
uintptr_t alignment_mask = alignment - 1;
|
||||
uintptr_t potential_allocation_begin = (current_begin_ + alignment_mask) & ~alignment_mask;
|
||||
uintptr_t potential_allocation_end = potential_allocation_begin + size;
|
||||
const uintptr_t alignment_mask = alignment - 1;
|
||||
const uintptr_t potential_allocation_begin = (current_begin_ + alignment_mask) &
|
||||
~alignment_mask;
|
||||
const uintptr_t potential_allocation_end = potential_allocation_begin + size;
|
||||
|
||||
if (potential_allocation_end <= current_end_) {
|
||||
current_begin_ = potential_allocation_end;
|
||||
|
@ -140,7 +141,7 @@ template<typename Allocator = GuardedAllocator> class LinearAllocator : NonCopya
|
|||
*/
|
||||
StringRefNull copy_string(StringRef str)
|
||||
{
|
||||
uint alloc_size = str.size() + 1;
|
||||
const uint alloc_size = str.size() + 1;
|
||||
char *buffer = (char *)this->allocate(alloc_size, 1);
|
||||
str.copy(buffer, alloc_size);
|
||||
return StringRefNull((const char *)buffer);
|
||||
|
@ -205,7 +206,8 @@ template<typename Allocator = GuardedAllocator> class LinearAllocator : NonCopya
|
|||
}
|
||||
}
|
||||
|
||||
uint size_in_bytes = power_of_2_min_u(std::max(min_allocation_size, next_min_alloc_size_));
|
||||
const uint size_in_bytes = power_of_2_min_u(
|
||||
std::max(min_allocation_size, next_min_alloc_size_));
|
||||
next_min_alloc_size_ = size_in_bytes * 2;
|
||||
|
||||
void *buffer = allocator_.allocate(size_in_bytes, 8, AT);
|
||||
|
|
|
@ -68,7 +68,7 @@ class LinearProbingStrategy {
|
|||
uint32_t hash_;
|
||||
|
||||
public:
|
||||
LinearProbingStrategy(uint32_t hash) : hash_(hash)
|
||||
LinearProbingStrategy(const uint32_t hash) : hash_(hash)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,7 @@ class QuadraticProbingStrategy {
|
|||
uint32_t iteration_;
|
||||
|
||||
public:
|
||||
QuadraticProbingStrategy(uint32_t hash)
|
||||
QuadraticProbingStrategy(const uint32_t hash)
|
||||
: original_hash_(hash), current_hash_(hash), iteration_(1)
|
||||
{
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ template<uint32_t LinearSteps = 1, bool PreShuffle = false> class PythonProbingS
|
|||
uint32_t perturb_;
|
||||
|
||||
public:
|
||||
PythonProbingStrategy(uint32_t hash) : hash_(hash), perturb_(hash)
|
||||
PythonProbingStrategy(const uint32_t hash) : hash_(hash), perturb_(hash)
|
||||
{
|
||||
if (PreShuffle) {
|
||||
this->next();
|
||||
|
@ -179,7 +179,7 @@ template<uint32_t LinearSteps = 2, bool PreShuffle = false> class ShuffleProbing
|
|||
uint32_t perturb_;
|
||||
|
||||
public:
|
||||
ShuffleProbingStrategy(uint32_t hash) : hash_(hash), perturb_(hash)
|
||||
ShuffleProbingStrategy(const uint32_t hash) : hash_(hash), perturb_(hash)
|
||||
{
|
||||
if (PreShuffle) {
|
||||
this->next();
|
||||
|
|
|
@ -493,7 +493,7 @@ class Set {
|
|||
* Potentially resize the set such that it can hold the specified number of keys without another
|
||||
* grow operation.
|
||||
*/
|
||||
void reserve(uint32_t n)
|
||||
void reserve(const uint32_t n)
|
||||
{
|
||||
if (usable_slots_ < n) {
|
||||
this->realloc_and_reinsert(n);
|
||||
|
@ -527,12 +527,12 @@ class Set {
|
|||
}
|
||||
|
||||
private:
|
||||
BLI_NOINLINE void realloc_and_reinsert(uint32_t min_usable_slots)
|
||||
BLI_NOINLINE void realloc_and_reinsert(const uint32_t min_usable_slots)
|
||||
{
|
||||
uint32_t total_slots, usable_slots;
|
||||
max_load_factor_.compute_total_and_usable_slots(
|
||||
SlotArray::inline_buffer_capacity(), min_usable_slots, &total_slots, &usable_slots);
|
||||
uint32_t new_slot_mask = total_slots - 1;
|
||||
const uint32_t new_slot_mask = total_slots - 1;
|
||||
|
||||
/**
|
||||
* Optimize the case when the set was empty beforehand. We can avoid some copies here.
|
||||
|
@ -568,9 +568,9 @@ class Set {
|
|||
|
||||
void add_after_grow_and_destruct_old(Slot &old_slot,
|
||||
SlotArray &new_slots,
|
||||
uint32_t new_slot_mask)
|
||||
const uint32_t new_slot_mask)
|
||||
{
|
||||
uint32_t hash = old_slot.get_hash(Hash());
|
||||
const uint32_t hash = old_slot.get_hash(Hash());
|
||||
|
||||
SLOT_PROBING_BEGIN (ProbingStrategy, hash, new_slot_mask, slot_index) {
|
||||
Slot &slot = new_slots[slot_index];
|
||||
|
@ -582,7 +582,8 @@ class Set {
|
|||
SLOT_PROBING_END();
|
||||
}
|
||||
|
||||
template<typename ForwardKey> bool contains__impl(const ForwardKey &key, uint32_t hash) const
|
||||
template<typename ForwardKey>
|
||||
bool contains__impl(const ForwardKey &key, const uint32_t hash) const
|
||||
{
|
||||
SET_SLOT_PROBING_BEGIN (hash, slot) {
|
||||
if (slot.is_empty()) {
|
||||
|
@ -595,7 +596,7 @@ class Set {
|
|||
SET_SLOT_PROBING_END();
|
||||
}
|
||||
|
||||
template<typename ForwardKey> void add_new__impl(ForwardKey &&key, uint32_t hash)
|
||||
template<typename ForwardKey> void add_new__impl(ForwardKey &&key, const uint32_t hash)
|
||||
{
|
||||
BLI_assert(!this->contains_as(key));
|
||||
|
||||
|
@ -611,7 +612,7 @@ class Set {
|
|||
SET_SLOT_PROBING_END();
|
||||
}
|
||||
|
||||
template<typename ForwardKey> bool add__impl(ForwardKey &&key, uint32_t hash)
|
||||
template<typename ForwardKey> bool add__impl(ForwardKey &&key, const uint32_t hash)
|
||||
{
|
||||
this->ensure_can_add();
|
||||
|
||||
|
@ -628,7 +629,7 @@ class Set {
|
|||
SET_SLOT_PROBING_END();
|
||||
}
|
||||
|
||||
template<typename ForwardKey> bool remove__impl(const ForwardKey &key, uint32_t hash)
|
||||
template<typename ForwardKey> bool remove__impl(const ForwardKey &key, const uint32_t hash)
|
||||
{
|
||||
SET_SLOT_PROBING_BEGIN (hash, slot) {
|
||||
if (slot.contains(key, is_equal_, hash)) {
|
||||
|
@ -643,7 +644,8 @@ class Set {
|
|||
SET_SLOT_PROBING_END();
|
||||
}
|
||||
|
||||
template<typename ForwardKey> void remove_contained__impl(const ForwardKey &key, uint32_t hash)
|
||||
template<typename ForwardKey>
|
||||
void remove_contained__impl(const ForwardKey &key, const uint32_t hash)
|
||||
{
|
||||
BLI_assert(this->contains_as(key));
|
||||
removed_slots_++;
|
||||
|
@ -658,7 +660,7 @@ class Set {
|
|||
}
|
||||
|
||||
template<typename ForwardKey>
|
||||
uint32_t count_collisions__impl(const ForwardKey &key, uint32_t hash) const
|
||||
uint32_t count_collisions__impl(const ForwardKey &key, const uint32_t hash) const
|
||||
{
|
||||
uint32_t collisions = 0;
|
||||
|
||||
|
|
|
@ -260,7 +260,7 @@ template<typename Key> class HashedSetSlot {
|
|||
return hash_;
|
||||
}
|
||||
|
||||
void relocate_occupied_here(HashedSetSlot &other, uint32_t hash)
|
||||
void relocate_occupied_here(HashedSetSlot &other, const uint32_t hash)
|
||||
{
|
||||
BLI_assert(!this->is_occupied());
|
||||
BLI_assert(other.is_occupied());
|
||||
|
@ -271,7 +271,7 @@ template<typename Key> class HashedSetSlot {
|
|||
}
|
||||
|
||||
template<typename ForwardKey, typename IsEqual>
|
||||
bool contains(const ForwardKey &key, const IsEqual &is_equal, uint32_t hash) const
|
||||
bool contains(const ForwardKey &key, const IsEqual &is_equal, const uint32_t hash) const
|
||||
{
|
||||
/* hash_ might be uninitialized here, but that is ok. */
|
||||
if (hash_ == hash) {
|
||||
|
@ -282,7 +282,7 @@ template<typename Key> class HashedSetSlot {
|
|||
return false;
|
||||
}
|
||||
|
||||
template<typename ForwardKey> void occupy(ForwardKey &&key, uint32_t hash)
|
||||
template<typename ForwardKey> void occupy(ForwardKey &&key, const uint32_t hash)
|
||||
{
|
||||
BLI_assert(!this->is_occupied());
|
||||
state_ = Occupied;
|
||||
|
@ -342,7 +342,7 @@ template<typename Key, typename KeyInfo> class IntrusiveSetSlot {
|
|||
return hash(key_);
|
||||
}
|
||||
|
||||
void relocate_occupied_here(IntrusiveSetSlot &other, uint32_t UNUSED(hash))
|
||||
void relocate_occupied_here(IntrusiveSetSlot &other, const uint32_t UNUSED(hash))
|
||||
{
|
||||
BLI_assert(!this->is_occupied());
|
||||
BLI_assert(other.is_occupied());
|
||||
|
@ -351,13 +351,13 @@ template<typename Key, typename KeyInfo> class IntrusiveSetSlot {
|
|||
}
|
||||
|
||||
template<typename ForwardKey, typename IsEqual>
|
||||
bool contains(const ForwardKey &key, const IsEqual &is_equal, uint32_t UNUSED(hash)) const
|
||||
bool contains(const ForwardKey &key, const IsEqual &is_equal, const uint32_t UNUSED(hash)) const
|
||||
{
|
||||
BLI_assert(KeyInfo::is_not_empty_or_removed(key));
|
||||
return is_equal(key_, key);
|
||||
}
|
||||
|
||||
template<typename ForwardKey> void occupy(ForwardKey &&key, uint32_t UNUSED(hash))
|
||||
template<typename ForwardKey> void occupy(ForwardKey &&key, const uint32_t UNUSED(hash))
|
||||
{
|
||||
BLI_assert(!this->is_occupied());
|
||||
BLI_assert(KeyInfo::is_not_empty_or_removed(key));
|
||||
|
|
|
@ -359,7 +359,7 @@ template<typename T> class Span {
|
|||
*/
|
||||
uint first_index(const T &search_value) const
|
||||
{
|
||||
int index = this->first_index_try(search_value);
|
||||
const int index = this->first_index_try(search_value);
|
||||
BLI_assert(index >= 0);
|
||||
return (uint)index;
|
||||
}
|
||||
|
@ -432,7 +432,7 @@ template<typename T> class MutableSpan {
|
|||
public:
|
||||
MutableSpan() = default;
|
||||
|
||||
MutableSpan(T *start, uint size) : start_(start), size_(size)
|
||||
MutableSpan(T *start, const uint size) : start_(start), size_(size)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -511,7 +511,7 @@ template<typename T> class MutableSpan {
|
|||
return start_ + size_;
|
||||
}
|
||||
|
||||
T &operator[](uint index) const
|
||||
T &operator[](const uint index) const
|
||||
{
|
||||
BLI_assert(index < this->size());
|
||||
return start_[index];
|
||||
|
@ -521,7 +521,7 @@ template<typename T> class MutableSpan {
|
|||
* Returns a contiguous part of the array. This invokes undefined behavior when the slice would
|
||||
* go out of bounds.
|
||||
*/
|
||||
MutableSpan slice(uint start, uint length) const
|
||||
MutableSpan slice(const uint start, const uint length) const
|
||||
{
|
||||
BLI_assert(start + length <= this->size());
|
||||
return MutableSpan(start_ + start, length);
|
||||
|
@ -531,7 +531,7 @@ template<typename T> class MutableSpan {
|
|||
* Returns a new MutableSpan with n elements removed from the beginning. This invokes
|
||||
* undefined behavior when the array is too small.
|
||||
*/
|
||||
MutableSpan drop_front(uint n) const
|
||||
MutableSpan drop_front(const uint n) const
|
||||
{
|
||||
BLI_assert(n <= this->size());
|
||||
return this->slice(n, this->size() - n);
|
||||
|
@ -541,7 +541,7 @@ template<typename T> class MutableSpan {
|
|||
* Returns a new MutableSpan with n elements removed from the end. This invokes undefined
|
||||
* behavior when the array is too small.
|
||||
*/
|
||||
MutableSpan drop_back(uint n) const
|
||||
MutableSpan drop_back(const uint n) const
|
||||
{
|
||||
BLI_assert(n <= this->size());
|
||||
return this->slice(0, this->size() - n);
|
||||
|
@ -551,7 +551,7 @@ template<typename T> class MutableSpan {
|
|||
* Returns a new MutableSpan that only contains the first n elements. This invokes undefined
|
||||
* behavior when the array is too small.
|
||||
*/
|
||||
MutableSpan take_front(uint n) const
|
||||
MutableSpan take_front(const uint n) const
|
||||
{
|
||||
BLI_assert(n <= this->size());
|
||||
return this->slice(0, n);
|
||||
|
@ -561,7 +561,7 @@ template<typename T> class MutableSpan {
|
|||
* Return a new MutableSpan that only contains the last n elements. This invokes undefined
|
||||
* behavior when the array is too small.
|
||||
*/
|
||||
MutableSpan take_back(uint n) const
|
||||
MutableSpan take_back(const uint n) const
|
||||
{
|
||||
BLI_assert(n <= this->size());
|
||||
return this->slice(this->size() - n, n);
|
||||
|
|
|
@ -296,8 +296,8 @@ class Stack {
|
|||
this->activate_next_chunk(remaining_values.size());
|
||||
}
|
||||
|
||||
uint remaining_capacity = top_chunk_->capacity_end - top_;
|
||||
uint amount = std::min(remaining_values.size(), remaining_capacity);
|
||||
const uint remaining_capacity = top_chunk_->capacity_end - top_;
|
||||
const uint amount = std::min(remaining_values.size(), remaining_capacity);
|
||||
uninitialized_copy_n(remaining_values.data(), amount, top_);
|
||||
top_ += amount;
|
||||
|
||||
|
@ -347,11 +347,11 @@ class Stack {
|
|||
*
|
||||
* This invokes undefined behavior when the currently active chunk is not full.
|
||||
*/
|
||||
void activate_next_chunk(uint size_hint)
|
||||
void activate_next_chunk(const uint size_hint)
|
||||
{
|
||||
BLI_assert(top_ == top_chunk_->capacity_end);
|
||||
if (top_chunk_->above == nullptr) {
|
||||
uint new_capacity = std::max(size_hint, top_chunk_->capacity() * 2 + 10);
|
||||
const uint new_capacity = std::max(size_hint, top_chunk_->capacity() * 2 + 10);
|
||||
|
||||
/* Do a single memory allocation for the Chunk and the array it references. */
|
||||
void *buffer = allocator_.allocate(
|
||||
|
|
|
@ -62,7 +62,7 @@ class StringRefBase {
|
|||
const char *data_;
|
||||
uint size_;
|
||||
|
||||
StringRefBase(const char *data, uint size) : data_(data), size_(size)
|
||||
StringRefBase(const char *data, const uint size) : data_(data), size_(size)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ class StringRefBase {
|
|||
* Copy the string into a buffer. The copied string will be null-terminated. This invokes
|
||||
* undefined behavior when dst_size is too small. (Should we define the behavior?)
|
||||
*/
|
||||
void copy(char *dst, uint dst_size) const
|
||||
void copy(char *dst, const uint dst_size) const
|
||||
{
|
||||
if (size_ < dst_size) {
|
||||
this->unsafe_copy(dst);
|
||||
|
@ -152,7 +152,7 @@ class StringRefBase {
|
|||
*/
|
||||
bool endswith(StringRef suffix) const;
|
||||
|
||||
StringRef substr(uint start, uint size) const;
|
||||
StringRef substr(uint start, const uint size) const;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -178,7 +178,7 @@ class StringRefNull : public StringRefBase {
|
|||
* Construct a StringRefNull from a null terminated c-string. This invokes undefined behavior
|
||||
* when the given size is not the correct size of the string.
|
||||
*/
|
||||
StringRefNull(const char *str, uint size) : StringRefBase(str, size)
|
||||
StringRefNull(const char *str, const uint size) : StringRefBase(str, size)
|
||||
{
|
||||
BLI_assert((uint)strlen(str) == size);
|
||||
}
|
||||
|
@ -194,7 +194,7 @@ class StringRefNull : public StringRefBase {
|
|||
/**
|
||||
* Get the char at the given index.
|
||||
*/
|
||||
char operator[](uint index) const
|
||||
char operator[](const uint index) const
|
||||
{
|
||||
/* Use '<=' instead of just '<', so that the null character can be accessed as well. */
|
||||
BLI_assert(index <= size_);
|
||||
|
@ -225,7 +225,7 @@ class StringRef : public StringRefBase {
|
|||
{
|
||||
}
|
||||
|
||||
StringRef(const char *str, uint length) : StringRefBase(str, length)
|
||||
StringRef(const char *str, const uint length) : StringRefBase(str, length)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -250,7 +250,7 @@ class StringRef : public StringRefBase {
|
|||
/**
|
||||
* Return a new StringRef that does not contain the first n chars.
|
||||
*/
|
||||
StringRef drop_prefix(uint n) const
|
||||
StringRef drop_prefix(const uint n) const
|
||||
{
|
||||
BLI_assert(n <= size_);
|
||||
return StringRef(data_ + n, size_ - n);
|
||||
|
@ -337,7 +337,7 @@ inline bool StringRefBase::endswith(StringRef suffix) const
|
|||
if (size_ < suffix.size_) {
|
||||
return false;
|
||||
}
|
||||
uint offset = size_ - suffix.size_;
|
||||
const uint offset = size_ - suffix.size_;
|
||||
for (uint i = 0; i < suffix.size_; i++) {
|
||||
if (data_[offset + i] != suffix.data_[i]) {
|
||||
return false;
|
||||
|
@ -349,7 +349,7 @@ inline bool StringRefBase::endswith(StringRef suffix) const
|
|||
/**
|
||||
* Return a new #StringRef containing only a sub-string of the original string.
|
||||
*/
|
||||
inline StringRef StringRefBase::substr(uint start, uint size) const
|
||||
inline StringRef StringRefBase::substr(const uint start, const uint size) const
|
||||
{
|
||||
BLI_assert(start + size <= size_);
|
||||
return StringRef(data_ + start, size);
|
||||
|
|
|
@ -45,8 +45,8 @@ class ScopedTimer {
|
|||
|
||||
~ScopedTimer()
|
||||
{
|
||||
TimePoint end = Clock::now();
|
||||
Nanoseconds duration = end - start_;
|
||||
const TimePoint end = Clock::now();
|
||||
const Nanoseconds duration = end - start_;
|
||||
|
||||
std::cout << "Timer '" << name_ << "' took ";
|
||||
print_duration(duration);
|
||||
|
|
|
@ -161,7 +161,7 @@ class Vector {
|
|||
*/
|
||||
Vector(Span<T> values) : Vector()
|
||||
{
|
||||
uint size = values.size();
|
||||
const uint size = values.size();
|
||||
this->reserve(size);
|
||||
this->increase_size_by_unchecked(size);
|
||||
blender::uninitialized_copy_n(values.data(), size, begin_);
|
||||
|
@ -222,7 +222,7 @@ class Vector {
|
|||
Vector(Vector<T, OtherInlineBufferCapacity, Allocator> &&other) noexcept
|
||||
: allocator_(other.allocator_)
|
||||
{
|
||||
uint size = other.size();
|
||||
const uint size = other.size();
|
||||
|
||||
if (other.is_inline()) {
|
||||
if (size <= InlineBufferCapacity) {
|
||||
|
@ -234,7 +234,7 @@ class Vector {
|
|||
}
|
||||
else {
|
||||
/* Copy from inline buffer to newly allocated buffer. */
|
||||
uint capacity = size;
|
||||
const uint capacity = size;
|
||||
begin_ = (T *)allocator_.allocate(sizeof(T) * capacity, alignof(T), AT);
|
||||
end_ = begin_ + size;
|
||||
capacity_end_ = begin_ + capacity;
|
||||
|
@ -330,7 +330,7 @@ class Vector {
|
|||
* This won't necessarily make an allocation when min_capacity is small.
|
||||
* The actual size of the vector does not change.
|
||||
*/
|
||||
void reserve(uint min_capacity)
|
||||
void reserve(const uint min_capacity)
|
||||
{
|
||||
if (min_capacity > this->capacity()) {
|
||||
this->realloc_to_at_least(min_capacity);
|
||||
|
@ -343,9 +343,9 @@ class Vector {
|
|||
* destructed. If new_size is larger than the old size, the new elements at the end are default
|
||||
* constructed. If T is trivially constructible, the memory is not touched by this function.
|
||||
*/
|
||||
void resize(uint new_size)
|
||||
void resize(const uint new_size)
|
||||
{
|
||||
uint old_size = this->size();
|
||||
const uint old_size = this->size();
|
||||
if (new_size > old_size) {
|
||||
this->reserve(new_size);
|
||||
default_construct_n(begin_ + old_size, new_size - old_size);
|
||||
|
@ -363,9 +363,9 @@ class Vector {
|
|||
* destructed. If new_size is larger than the old size, the new elements will be copy constructed
|
||||
* from the given value.
|
||||
*/
|
||||
void resize(uint new_size, const T &value)
|
||||
void resize(const uint new_size, const T &value)
|
||||
{
|
||||
uint old_size = this->size();
|
||||
const uint old_size = this->size();
|
||||
if (new_size > old_size) {
|
||||
this->reserve(new_size);
|
||||
uninitialized_fill_n(begin_ + old_size, new_size - old_size, value);
|
||||
|
@ -428,7 +428,7 @@ class Vector {
|
|||
*/
|
||||
uint append_and_get_index(const T &value)
|
||||
{
|
||||
uint index = this->size();
|
||||
const uint index = this->size();
|
||||
this->append(value);
|
||||
return index;
|
||||
}
|
||||
|
@ -469,7 +469,7 @@ class Vector {
|
|||
* Insert the same element n times at the end of the vector.
|
||||
* This might result in a reallocation internally.
|
||||
*/
|
||||
void append_n_times(const T &value, uint n)
|
||||
void append_n_times(const T &value, const uint n)
|
||||
{
|
||||
this->reserve(this->size() + n);
|
||||
blender::uninitialized_fill_n(end_, n, value);
|
||||
|
@ -482,7 +482,7 @@ class Vector {
|
|||
* useful when you want to call constructors in the vector yourself. This should only be done in
|
||||
* very rare cases and has to be justified every time.
|
||||
*/
|
||||
void increase_size_by_unchecked(uint n)
|
||||
void increase_size_by_unchecked(const uint n)
|
||||
{
|
||||
BLI_assert(end_ + n <= capacity_end_);
|
||||
end_ += n;
|
||||
|
@ -614,7 +614,7 @@ class Vector {
|
|||
* Delete any element in the vector. The empty space will be filled by the previously last
|
||||
* element. This takes O(1) time.
|
||||
*/
|
||||
void remove_and_reorder(uint index)
|
||||
void remove_and_reorder(const uint index)
|
||||
{
|
||||
BLI_assert(index < this->size());
|
||||
T *element_to_remove = begin_ + index;
|
||||
|
@ -632,7 +632,7 @@ class Vector {
|
|||
*/
|
||||
void remove_first_occurrence_and_reorder(const T &value)
|
||||
{
|
||||
uint index = this->first_index_of(value);
|
||||
const uint index = this->first_index_of(value);
|
||||
this->remove_and_reorder((uint)index);
|
||||
}
|
||||
|
||||
|
@ -643,10 +643,10 @@ class Vector {
|
|||
*
|
||||
* This is similar to std::vector::erase.
|
||||
*/
|
||||
void remove(uint index)
|
||||
void remove(const uint index)
|
||||
{
|
||||
BLI_assert(index < this->size());
|
||||
uint last_index = this->size() - 1;
|
||||
const uint last_index = this->size() - 1;
|
||||
for (uint i = index; i < last_index; i++) {
|
||||
begin_[i] = std::move(begin_[i + 1]);
|
||||
}
|
||||
|
@ -661,7 +661,7 @@ class Vector {
|
|||
*/
|
||||
int first_index_of_try(const T &value) const
|
||||
{
|
||||
for (T *current = begin_; current != end_; current++) {
|
||||
for (const T *current = begin_; current != end_; current++) {
|
||||
if (*current == value) {
|
||||
return (int)(current - begin_);
|
||||
}
|
||||
|
@ -675,7 +675,7 @@ class Vector {
|
|||
*/
|
||||
uint first_index_of(const T &value) const
|
||||
{
|
||||
int index = this->first_index_of_try(value);
|
||||
const int index = this->first_index_of_try(value);
|
||||
BLI_assert(index >= 0);
|
||||
return (uint)index;
|
||||
}
|
||||
|
@ -780,7 +780,7 @@ class Vector {
|
|||
}
|
||||
}
|
||||
|
||||
BLI_NOINLINE void realloc_to_at_least(uint min_capacity)
|
||||
BLI_NOINLINE void realloc_to_at_least(const uint min_capacity)
|
||||
{
|
||||
if (this->capacity() >= min_capacity) {
|
||||
return;
|
||||
|
@ -788,10 +788,10 @@ class Vector {
|
|||
|
||||
/* At least double the size of the previous allocation. Otherwise consecutive calls to grow can
|
||||
* cause a reallocation every time even though min_capacity only increments. */
|
||||
uint min_new_capacity = this->capacity() * 2;
|
||||
const uint min_new_capacity = this->capacity() * 2;
|
||||
|
||||
uint new_capacity = std::max(min_capacity, min_new_capacity);
|
||||
uint size = this->size();
|
||||
const uint new_capacity = std::max(min_capacity, min_new_capacity);
|
||||
const uint size = this->size();
|
||||
|
||||
T *new_array = (T *)allocator_.allocate(new_capacity * (uint)sizeof(T), alignof(T), AT);
|
||||
uninitialized_relocate_n(begin_, size, new_array);
|
||||
|
@ -813,8 +813,8 @@ class Vector {
|
|||
{
|
||||
allocator_ = other.allocator_;
|
||||
|
||||
uint size = other.size();
|
||||
uint capacity = size;
|
||||
const uint size = other.size();
|
||||
uint capacity;
|
||||
|
||||
if (size <= InlineBufferCapacity) {
|
||||
begin_ = this->inline_buffer();
|
||||
|
|
|
@ -238,7 +238,7 @@ class VectorSet {
|
|||
/**
|
||||
* Get the key stored at the given position in the vector.
|
||||
*/
|
||||
const Key &operator[](uint32_t index) const
|
||||
const Key &operator[](const uint32_t index) const
|
||||
{
|
||||
BLI_assert(index <= this->size());
|
||||
return keys_[index];
|
||||
|
@ -488,7 +488,7 @@ class VectorSet {
|
|||
/**
|
||||
* Potentially resize the vector set such that it can hold n elements without doing another grow.
|
||||
*/
|
||||
void reserve(uint32_t n)
|
||||
void reserve(const uint32_t n)
|
||||
{
|
||||
if (usable_slots_ < n) {
|
||||
this->realloc_and_reinsert(n);
|
||||
|
@ -505,12 +505,12 @@ class VectorSet {
|
|||
}
|
||||
|
||||
private:
|
||||
BLI_NOINLINE void realloc_and_reinsert(uint32_t min_usable_slots)
|
||||
BLI_NOINLINE void realloc_and_reinsert(const uint32_t min_usable_slots)
|
||||
{
|
||||
uint32_t total_slots, usable_slots;
|
||||
max_load_factor_.compute_total_and_usable_slots(
|
||||
SlotArray::inline_buffer_capacity(), min_usable_slots, &total_slots, &usable_slots);
|
||||
uint32_t new_slot_mask = total_slots - 1;
|
||||
const uint32_t new_slot_mask = total_slots - 1;
|
||||
|
||||
/* Optimize the case when the set was empty beforehand. We can avoid some copies here. */
|
||||
if (this->size() == 0) {
|
||||
|
@ -549,10 +549,10 @@ class VectorSet {
|
|||
|
||||
void add_after_grow_and_destruct_old(Slot &old_slot,
|
||||
SlotArray &new_slots,
|
||||
uint32_t new_slot_mask)
|
||||
const uint32_t new_slot_mask)
|
||||
{
|
||||
const Key &key = keys_[old_slot.index()];
|
||||
uint32_t hash = old_slot.get_hash(key, Hash());
|
||||
const uint32_t hash = old_slot.get_hash(key, Hash());
|
||||
|
||||
SLOT_PROBING_BEGIN (ProbingStrategy, hash, new_slot_mask, slot_index) {
|
||||
Slot &slot = new_slots[slot_index];
|
||||
|
@ -564,7 +564,8 @@ class VectorSet {
|
|||
SLOT_PROBING_END();
|
||||
}
|
||||
|
||||
template<typename ForwardKey> bool contains__impl(const ForwardKey &key, uint32_t hash) const
|
||||
template<typename ForwardKey>
|
||||
bool contains__impl(const ForwardKey &key, const uint32_t hash) const
|
||||
{
|
||||
VECTOR_SET_SLOT_PROBING_BEGIN (hash, slot) {
|
||||
if (slot.is_empty()) {
|
||||
|
@ -577,7 +578,7 @@ class VectorSet {
|
|||
VECTOR_SET_SLOT_PROBING_END();
|
||||
}
|
||||
|
||||
template<typename ForwardKey> void add_new__impl(ForwardKey &&key, uint32_t hash)
|
||||
template<typename ForwardKey> void add_new__impl(ForwardKey &&key, const uint32_t hash)
|
||||
{
|
||||
BLI_assert(!this->contains_as(key));
|
||||
|
||||
|
@ -595,7 +596,7 @@ class VectorSet {
|
|||
VECTOR_SET_SLOT_PROBING_END();
|
||||
}
|
||||
|
||||
template<typename ForwardKey> bool add__impl(ForwardKey &&key, uint32_t hash)
|
||||
template<typename ForwardKey> bool add__impl(ForwardKey &&key, const uint32_t hash)
|
||||
{
|
||||
this->ensure_can_add();
|
||||
|
||||
|
@ -614,7 +615,8 @@ class VectorSet {
|
|||
VECTOR_SET_SLOT_PROBING_END();
|
||||
}
|
||||
|
||||
template<typename ForwardKey> uint32_t index_of__impl(const ForwardKey &key, uint32_t hash) const
|
||||
template<typename ForwardKey>
|
||||
uint32_t index_of__impl(const ForwardKey &key, const uint32_t hash) const
|
||||
{
|
||||
BLI_assert(this->contains_as(key));
|
||||
|
||||
|
@ -627,7 +629,7 @@ class VectorSet {
|
|||
}
|
||||
|
||||
template<typename ForwardKey>
|
||||
int32_t index_of_try__impl(const ForwardKey &key, uint32_t hash) const
|
||||
int32_t index_of_try__impl(const ForwardKey &key, const uint32_t hash) const
|
||||
{
|
||||
VECTOR_SET_SLOT_PROBING_BEGIN (hash, slot) {
|
||||
if (slot.contains(key, is_equal_, hash, keys_)) {
|
||||
|
@ -644,10 +646,10 @@ class VectorSet {
|
|||
{
|
||||
BLI_assert(this->size() > 0);
|
||||
|
||||
uint32_t index_to_pop = this->size() - 1;
|
||||
const uint32_t index_to_pop = this->size() - 1;
|
||||
Key key = std::move(keys_[index_to_pop]);
|
||||
keys_[index_to_pop].~Key();
|
||||
uint32_t hash = hash_(key);
|
||||
const uint32_t hash = hash_(key);
|
||||
|
||||
removed_slots_++;
|
||||
|
||||
|
@ -660,7 +662,7 @@ class VectorSet {
|
|||
VECTOR_SET_SLOT_PROBING_END();
|
||||
}
|
||||
|
||||
template<typename ForwardKey> bool remove__impl(const ForwardKey &key, uint32_t hash)
|
||||
template<typename ForwardKey> bool remove__impl(const ForwardKey &key, const uint32_t hash)
|
||||
{
|
||||
VECTOR_SET_SLOT_PROBING_BEGIN (hash, slot) {
|
||||
if (slot.contains(key, is_equal_, hash, keys_)) {
|
||||
|
@ -674,7 +676,8 @@ class VectorSet {
|
|||
VECTOR_SET_SLOT_PROBING_END();
|
||||
}
|
||||
|
||||
template<typename ForwardKey> void remove_contained__impl(const ForwardKey &key, uint32_t hash)
|
||||
template<typename ForwardKey>
|
||||
void remove_contained__impl(const ForwardKey &key, const uint32_t hash)
|
||||
{
|
||||
BLI_assert(this->contains_as(key));
|
||||
|
||||
|
@ -704,7 +707,7 @@ class VectorSet {
|
|||
return;
|
||||
}
|
||||
|
||||
void update_slot_index(const Key &key, uint32_t old_index, uint32_t new_index)
|
||||
void update_slot_index(const Key &key, const uint32_t old_index, const uint32_t new_index)
|
||||
{
|
||||
uint32_t hash = hash_(key);
|
||||
VECTOR_SET_SLOT_PROBING_BEGIN (hash, slot) {
|
||||
|
@ -717,7 +720,7 @@ class VectorSet {
|
|||
}
|
||||
|
||||
template<typename ForwardKey>
|
||||
uint32_t count_collisions__impl(const ForwardKey &key, uint32_t hash) const
|
||||
uint32_t count_collisions__impl(const ForwardKey &key, const uint32_t hash) const
|
||||
{
|
||||
uint32_t collisions = 0;
|
||||
|
||||
|
@ -741,7 +744,7 @@ class VectorSet {
|
|||
}
|
||||
}
|
||||
|
||||
Key *allocate_keys_array(uint32_t size)
|
||||
Key *allocate_keys_array(const uint32_t size)
|
||||
{
|
||||
return (Key *)slots_.allocator().allocate((uint32_t)sizeof(Key) * size, alignof(Key), AT);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue