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>2022-06-25 20:27:33 +0300
committerJacques Lucke <jacques@blender.org>2022-06-25 20:27:33 +0300
commit22fc0cbd6966c1e46a28038fca8ef59e8ce50660 (patch)
tree0f6bf65b27f60f7f313fa14daefa662eb3e4678e /source/blender/blenlib/BLI_virtual_array.hh
parent3237c6dbe877db1cfbe15e92f6cb267d8a6031ea (diff)
BLI: improve support for trivial virtual arrays
This commits reduces the number of function calls through function pointers in `blender::Any` when the stored type is trivial. Furthermore, this implements marks some classes as trivial, which we know are trivial but the compiler does not (the standard currently says that any class with a virtual destructor is non-trivial). Under some circumstances we know that final child classes are trivial though. This allows for some optimizations. Also see https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1077r0.html.
Diffstat (limited to 'source/blender/blenlib/BLI_virtual_array.hh')
-rw-r--r--source/blender/blenlib/BLI_virtual_array.hh13
1 files changed, 13 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_virtual_array.hh b/source/blender/blenlib/BLI_virtual_array.hh
index e34eac1a006..d0436bdc213 100644
--- a/source/blender/blenlib/BLI_virtual_array.hh
+++ b/source/blender/blenlib/BLI_virtual_array.hh
@@ -319,6 +319,9 @@ template<typename T> class VArrayImpl_For_Span_final final : public VArrayImpl_F
}
};
+template<typename T>
+inline constexpr bool is_trivial_extended_v<VArrayImpl_For_Span_final<T>> = true;
+
/**
* A variant of `VArrayImpl_For_Span` that owns the underlying data.
* The `Container` type has to implement a `size()` and `data()` method.
@@ -379,6 +382,9 @@ template<typename T> class VArrayImpl_For_Single final : public VArrayImpl<T> {
}
};
+template<typename T>
+inline constexpr bool is_trivial_extended_v<VArrayImpl_For_Single<T>> = is_trivial_extended_v<T>;
+
/**
* This class makes it easy to create a virtual array for an existing function or lambda. The
* `GetFunc` should take a single `index` argument and return the value at that index.
@@ -522,6 +528,13 @@ class VArrayImpl_For_DerivedSpan final : public VMutableArrayImpl<ElemT> {
}
};
+template<typename StructT,
+ typename ElemT,
+ ElemT (*GetFunc)(const StructT &),
+ void (*SetFunc)(StructT &, ElemT)>
+inline constexpr bool
+ is_trivial_extended_v<VArrayImpl_For_DerivedSpan<StructT, ElemT, GetFunc, SetFunc>> = true;
+
namespace detail {
/**