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_memory_utils.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_memory_utils.hh')
-rw-r--r--source/blender/blenlib/BLI_memory_utils.hh17
1 files changed, 16 insertions, 1 deletions
diff --git a/source/blender/blenlib/BLI_memory_utils.hh b/source/blender/blenlib/BLI_memory_utils.hh
index 940542c9f1d..c2ad3ea761a 100644
--- a/source/blender/blenlib/BLI_memory_utils.hh
+++ b/source/blender/blenlib/BLI_memory_utils.hh
@@ -19,6 +19,21 @@
namespace blender {
/**
+ * Under some circumstances #std::is_trivial_v<T> is false even though we know that the type is
+ * actually trivial. Using that extra knowledge allows for some optimizations.
+ */
+template<typename T> inline constexpr bool is_trivial_extended_v = std::is_trivial_v<T>;
+template<typename T>
+inline constexpr bool is_trivially_destructible_extended_v = is_trivial_extended_v<T> ||
+ std::is_trivially_destructible_v<T>;
+template<typename T>
+inline constexpr bool is_trivially_copy_constructible_extended_v =
+ is_trivial_extended_v<T> || std::is_trivially_copy_constructible_v<T>;
+template<typename T>
+inline constexpr bool is_trivially_move_constructible_extended_v =
+ is_trivial_extended_v<T> || std::is_trivially_move_constructible_v<T>;
+
+/**
* Call the destructor on n consecutive values. For trivially destructible types, this does
* nothing.
*
@@ -38,7 +53,7 @@ template<typename T> void destruct_n(T *ptr, int64_t n)
/* This is not strictly necessary, because the loop below will be optimized away anyway. It is
* nice to make behavior this explicitly, though. */
- if (std::is_trivially_destructible_v<T>) {
+ if (is_trivially_destructible_extended_v<T>) {
return;
}