Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2020-07-20 13:16:20 +0300
committerJacques Lucke <jacques@blender.org>2020-07-20 13:16:20 +0300
commit8cbbdedaf4dfec9e320e7e2be58b75d256950df1 (patch)
tree496b9620e11ac44e515b0bb4ca52c05834d557f9 /source/blender/functions/FN_cpp_type.hh
parent686ab4c9401a90b22fb17e46c992eb513fe4f693 (diff)
Refactor: Update integer type usage
This updates the usage of integer types in code I wrote according to our new style guides. Major changes: * Use signed instead of unsigned integers in many places. * C++ containers in blenlib use `int64_t` for size and indices now (instead of `uint`). * Hash values for C++ containers are 64 bit wide now (instead of 32 bit). I do hope that I broke no builds, but it is quite likely that some compiler reports slightly different errors. Please let me know when there are any errors. If the fix is small, feel free to commit it yourself. I compiled successfully on linux with gcc and on windows.
Diffstat (limited to 'source/blender/functions/FN_cpp_type.hh')
-rw-r--r--source/blender/functions/FN_cpp_type.hh92
1 files changed, 46 insertions, 46 deletions
diff --git a/source/blender/functions/FN_cpp_type.hh b/source/blender/functions/FN_cpp_type.hh
index ce02bfd05be..594890e353a 100644
--- a/source/blender/functions/FN_cpp_type.hh
+++ b/source/blender/functions/FN_cpp_type.hh
@@ -38,7 +38,7 @@
* methods come in three variants. Using the construct-default methods as example:
* - construct_default(void *ptr):
* Constructs a single instance of that type at the given pointer.
- * - construct_default_n(void *ptr, uint n):
+ * - construct_default_n(void *ptr, int64_t n):
* Constructs n instances of that type in an array that starts at the given pointer.
* - construct_default_indices(void *ptr, IndexMask mask):
* Constructs multiple instances of that type in an array that starts at the given pointer.
@@ -77,42 +77,42 @@ namespace blender::fn {
class CPPType : NonCopyable, NonMovable {
public:
using ConstructDefaultF = void (*)(void *ptr);
- using ConstructDefaultNF = void (*)(void *ptr, uint n);
+ using ConstructDefaultNF = void (*)(void *ptr, int64_t n);
using ConstructDefaultIndicesF = void (*)(void *ptr, IndexMask mask);
using DestructF = void (*)(void *ptr);
- using DestructNF = void (*)(void *ptr, uint n);
+ using DestructNF = void (*)(void *ptr, int64_t n);
using DestructIndicesF = void (*)(void *ptr, IndexMask mask);
using CopyToInitializedF = void (*)(const void *src, void *dst);
- using CopyToInitializedNF = void (*)(const void *src, void *dst, uint n);
+ using CopyToInitializedNF = void (*)(const void *src, void *dst, int64_t n);
using CopyToInitializedIndicesF = void (*)(const void *src, void *dst, IndexMask mask);
using CopyToUninitializedF = void (*)(const void *src, void *dst);
- using CopyToUninitializedNF = void (*)(const void *src, void *dst, uint n);
+ using CopyToUninitializedNF = void (*)(const void *src, void *dst, int64_t n);
using CopyToUninitializedIndicesF = void (*)(const void *src, void *dst, IndexMask mask);
using RelocateToInitializedF = void (*)(void *src, void *dst);
- using RelocateToInitializedNF = void (*)(void *src, void *dst, uint n);
+ using RelocateToInitializedNF = void (*)(void *src, void *dst, int64_t n);
using RelocateToInitializedIndicesF = void (*)(void *src, void *dst, IndexMask mask);
using RelocateToUninitializedF = void (*)(void *src, void *dst);
- using RelocateToUninitializedNF = void (*)(void *src, void *dst, uint n);
+ using RelocateToUninitializedNF = void (*)(void *src, void *dst, int64_t n);
using RelocateToUninitializedIndicesF = void (*)(void *src, void *dst, IndexMask mask);
- using FillInitializedF = void (*)(const void *value, void *dst, uint n);
+ using FillInitializedF = void (*)(const void *value, void *dst, int64_t n);
using FillInitializedIndicesF = void (*)(const void *value, void *dst, IndexMask mask);
- using FillUninitializedF = void (*)(const void *value, void *dst, uint n);
+ using FillUninitializedF = void (*)(const void *value, void *dst, int64_t n);
using FillUninitializedIndicesF = void (*)(const void *value, void *dst, IndexMask mask);
using DebugPrintF = void (*)(const void *value, std::stringstream &ss);
using IsEqualF = bool (*)(const void *a, const void *b);
- using HashF = uint32_t (*)(const void *value);
+ using HashF = uint64_t (*)(const void *value);
private:
- uint size_;
- uint alignment_;
+ int64_t size_;
+ int64_t alignment_;
uintptr_t alignment_mask_;
bool is_trivially_destructible_;
@@ -155,8 +155,8 @@ class CPPType : NonCopyable, NonMovable {
public:
CPPType(std::string name,
- uint size,
- uint alignment,
+ int64_t size,
+ int64_t alignment,
bool is_trivially_destructible,
ConstructDefaultF construct_default,
ConstructDefaultNF construct_default_n,
@@ -250,7 +250,7 @@ class CPPType : NonCopyable, NonMovable {
* C++ equivalent:
* sizeof(T);
*/
- uint size() const
+ int64_t size() const
{
return size_;
}
@@ -261,7 +261,7 @@ class CPPType : NonCopyable, NonMovable {
* C++ equivalent:
* alignof(T);
*/
- uint alignment() const
+ int64_t alignment() const
{
return alignment_;
}
@@ -306,7 +306,7 @@ class CPPType : NonCopyable, NonMovable {
construct_default_(ptr);
}
- void construct_default_n(void *ptr, uint n) const
+ void construct_default_n(void *ptr, int64_t n) const
{
BLI_assert(n == 0 || this->pointer_can_point_to_instance(ptr));
@@ -335,7 +335,7 @@ class CPPType : NonCopyable, NonMovable {
destruct_(ptr);
}
- void destruct_n(void *ptr, uint n) const
+ void destruct_n(void *ptr, int64_t n) const
{
BLI_assert(n == 0 || this->pointer_can_point_to_instance(ptr));
@@ -369,7 +369,7 @@ class CPPType : NonCopyable, NonMovable {
copy_to_initialized_(src, dst);
}
- void copy_to_initialized_n(const void *src, void *dst, uint n) const
+ void copy_to_initialized_n(const void *src, void *dst, int64_t n) const
{
BLI_assert(src != dst);
BLI_assert(n == 0 || this->pointer_can_point_to_instance(src));
@@ -404,7 +404,7 @@ class CPPType : NonCopyable, NonMovable {
copy_to_uninitialized_(src, dst);
}
- void copy_to_uninitialized_n(const void *src, void *dst, uint n) const
+ void copy_to_uninitialized_n(const void *src, void *dst, int64_t n) const
{
BLI_assert(src != dst);
BLI_assert(n == 0 || this->pointer_can_point_to_instance(src));
@@ -439,7 +439,7 @@ class CPPType : NonCopyable, NonMovable {
relocate_to_initialized_(src, dst);
}
- void relocate_to_initialized_n(void *src, void *dst, uint n) const
+ void relocate_to_initialized_n(void *src, void *dst, int64_t n) const
{
BLI_assert(src != dst);
BLI_assert(n == 0 || this->pointer_can_point_to_instance(src));
@@ -474,7 +474,7 @@ class CPPType : NonCopyable, NonMovable {
relocate_to_uninitialized_(src, dst);
}
- void relocate_to_uninitialized_n(void *src, void *dst, uint n) const
+ void relocate_to_uninitialized_n(void *src, void *dst, int64_t n) const
{
BLI_assert(src != dst);
BLI_assert(n == 0 || this->pointer_can_point_to_instance(src));
@@ -497,7 +497,7 @@ class CPPType : NonCopyable, NonMovable {
*
* Other instances of the same type should live in the array before this method is called.
*/
- void fill_initialized(const void *value, void *dst, uint n) const
+ void fill_initialized(const void *value, void *dst, int64_t n) const
{
BLI_assert(n == 0 || this->pointer_can_point_to_instance(value));
BLI_assert(n == 0 || this->pointer_can_point_to_instance(dst));
@@ -518,7 +518,7 @@ class CPPType : NonCopyable, NonMovable {
*
* The array should be uninitialized before this method is called.
*/
- void fill_uninitialized(const void *value, void *dst, uint n) const
+ void fill_uninitialized(const void *value, void *dst, int64_t n) const
{
BLI_assert(n == 0 || this->pointer_can_point_to_instance(value));
BLI_assert(n == 0 || this->pointer_can_point_to_instance(dst));
@@ -547,7 +547,7 @@ class CPPType : NonCopyable, NonMovable {
return is_equal_(a, b);
}
- uint32_t hash(const void *value) const
+ uint64_t hash(const void *value) const
{
BLI_assert(this->pointer_can_point_to_instance(value));
return hash_(value);
@@ -562,7 +562,7 @@ class CPPType : NonCopyable, NonMovable {
return default_value_;
}
- uint32_t hash() const
+ uint64_t hash() const
{
return DefaultHash<const CPPType *>{}(this);
}
@@ -583,39 +583,39 @@ template<typename T> void construct_default_cb(void *ptr)
{
new (ptr) T;
}
-template<typename T> void construct_default_n_cb(void *ptr, uint n)
+template<typename T> void construct_default_n_cb(void *ptr, int64_t n)
{
blender::default_construct_n((T *)ptr, n);
}
template<typename T> void construct_default_indices_cb(void *ptr, IndexMask mask)
{
- mask.foreach_index([&](uint i) { new ((T *)ptr + i) T; });
+ mask.foreach_index([&](int64_t i) { new ((T *)ptr + i) T; });
}
template<typename T> void destruct_cb(void *ptr)
{
((T *)ptr)->~T();
}
-template<typename T> void destruct_n_cb(void *ptr, uint n)
+template<typename T> void destruct_n_cb(void *ptr, int64_t n)
{
blender::destruct_n((T *)ptr, n);
}
template<typename T> void destruct_indices_cb(void *ptr, IndexMask mask)
{
T *ptr_ = (T *)ptr;
- mask.foreach_index([&](uint i) { ptr_[i].~T(); });
+ mask.foreach_index([&](int64_t i) { ptr_[i].~T(); });
}
template<typename T> void copy_to_initialized_cb(const void *src, void *dst)
{
*(T *)dst = *(T *)src;
}
-template<typename T> void copy_to_initialized_n_cb(const void *src, void *dst, uint n)
+template<typename T> void copy_to_initialized_n_cb(const void *src, void *dst, int64_t n)
{
const T *src_ = (const T *)src;
T *dst_ = (T *)dst;
- for (uint i = 0; i < n; i++) {
+ for (int64_t i = 0; i < n; i++) {
dst_[i] = src_[i];
}
}
@@ -625,14 +625,14 @@ void copy_to_initialized_indices_cb(const void *src, void *dst, IndexMask mask)
const T *src_ = (const T *)src;
T *dst_ = (T *)dst;
- mask.foreach_index([&](uint i) { dst_[i] = src_[i]; });
+ mask.foreach_index([&](int64_t i) { dst_[i] = src_[i]; });
}
template<typename T> void copy_to_uninitialized_cb(const void *src, void *dst)
{
blender::uninitialized_copy_n((T *)src, 1, (T *)dst);
}
-template<typename T> void copy_to_uninitialized_n_cb(const void *src, void *dst, uint n)
+template<typename T> void copy_to_uninitialized_n_cb(const void *src, void *dst, int64_t n)
{
blender::uninitialized_copy_n((T *)src, n, (T *)dst);
}
@@ -642,7 +642,7 @@ void copy_to_uninitialized_indices_cb(const void *src, void *dst, IndexMask mask
const T *src_ = (const T *)src;
T *dst_ = (T *)dst;
- mask.foreach_index([&](uint i) { new (dst_ + i) T(src_[i]); });
+ mask.foreach_index([&](int64_t i) { new (dst_ + i) T(src_[i]); });
}
template<typename T> void relocate_to_initialized_cb(void *src, void *dst)
@@ -653,7 +653,7 @@ template<typename T> void relocate_to_initialized_cb(void *src, void *dst)
*dst_ = std::move(*src_);
src_->~T();
}
-template<typename T> void relocate_to_initialized_n_cb(void *src, void *dst, uint n)
+template<typename T> void relocate_to_initialized_n_cb(void *src, void *dst, int64_t n)
{
blender::initialized_relocate_n((T *)src, n, (T *)dst);
}
@@ -662,7 +662,7 @@ template<typename T> void relocate_to_initialized_indices_cb(void *src, void *ds
T *src_ = (T *)src;
T *dst_ = (T *)dst;
- mask.foreach_index([&](uint i) {
+ mask.foreach_index([&](int64_t i) {
dst_[i] = std::move(src_[i]);
src_[i].~T();
});
@@ -676,7 +676,7 @@ template<typename T> void relocate_to_uninitialized_cb(void *src, void *dst)
new (dst_) T(std::move(*src_));
src_->~T();
}
-template<typename T> void relocate_to_uninitialized_n_cb(void *src, void *dst, uint n)
+template<typename T> void relocate_to_uninitialized_n_cb(void *src, void *dst, int64_t n)
{
blender::uninitialized_relocate_n((T *)src, n, (T *)dst);
}
@@ -686,18 +686,18 @@ void relocate_to_uninitialized_indices_cb(void *src, void *dst, IndexMask mask)
T *src_ = (T *)src;
T *dst_ = (T *)dst;
- mask.foreach_index([&](uint i) {
+ mask.foreach_index([&](int64_t i) {
new (dst_ + i) T(std::move(src_[i]));
src_[i].~T();
});
}
-template<typename T> void fill_initialized_cb(const void *value, void *dst, uint n)
+template<typename T> void fill_initialized_cb(const void *value, void *dst, int64_t n)
{
const T &value_ = *(const T *)value;
T *dst_ = (T *)dst;
- for (uint i = 0; i < n; i++) {
+ for (int64_t i = 0; i < n; i++) {
dst_[i] = value_;
}
}
@@ -706,15 +706,15 @@ template<typename T> void fill_initialized_indices_cb(const void *value, void *d
const T &value_ = *(const T *)value;
T *dst_ = (T *)dst;
- mask.foreach_index([&](uint i) { dst_[i] = value_; });
+ mask.foreach_index([&](int64_t i) { dst_[i] = value_; });
}
-template<typename T> void fill_uninitialized_cb(const void *value, void *dst, uint n)
+template<typename T> void fill_uninitialized_cb(const void *value, void *dst, int64_t n)
{
const T &value_ = *(const T *)value;
T *dst_ = (T *)dst;
- for (uint i = 0; i < n; i++) {
+ for (int64_t i = 0; i < n; i++) {
new (dst_ + i) T(value_);
}
}
@@ -724,7 +724,7 @@ void fill_uninitialized_indices_cb(const void *value, void *dst, IndexMask mask)
const T &value_ = *(const T *)value;
T *dst_ = (T *)dst;
- mask.foreach_index([&](uint i) { new (dst_ + i) T(value_); });
+ mask.foreach_index([&](int64_t i) { new (dst_ + i) T(value_); });
}
template<typename T> void debug_print_cb(const void *value, std::stringstream &ss)
@@ -740,7 +740,7 @@ template<typename T> bool is_equal_cb(const void *a, const void *b)
return a_ == b_;
}
-template<typename T> uint32_t hash_cb(const void *value)
+template<typename T> uint64_t hash_cb(const void *value)
{
const T &value_ = *(const T *)value;
return DefaultHash<T>{}(value_);