mirror of
https://github.com/blender/blender
synced 2026-09-26 16:15:47 +03:00
BLI: avoid compiling same function multiple times for trivial types
For example, copying and moving a trivial type ends is the same. However, currently we generate the code for both cases independently instead of reusing the same underlying function. This reduces the size of the Blender binary from `218.548.896` to `218.355.552` bytes for me. So it's a reduction of about 200kb. It's probably possible to reduce this even more, but that's for another day. The main tricky thing here is telling the compiler that a `const` from a function parameter can be cast away for trivial types (see code comment). Maybe there is a better way to do this while making sure the compiler doesn't generate unnecessary code. Pull Request: https://projects.blender.org/blender/blender/pulls/119601
This commit is contained in:
parent
3ad4ea81d1
commit
dc762d0914
1 changed files with 50 additions and 14 deletions
|
|
@ -244,33 +244,69 @@ CPPType::CPPType(TypeTag<T> /*type*/,
|
|||
copy_assign_compressed_ = copy_assign_compressed_cb<T>;
|
||||
}
|
||||
if constexpr (std::is_copy_constructible_v<T>) {
|
||||
copy_construct_ = copy_construct_cb<T>;
|
||||
copy_construct_indices_ = copy_construct_indices_cb<T>;
|
||||
copy_construct_compressed_ = copy_construct_compressed_cb<T>;
|
||||
if constexpr (std::is_trivially_copy_constructible_v<T>) {
|
||||
copy_construct_ = copy_assign_;
|
||||
copy_construct_indices_ = copy_assign_indices_;
|
||||
copy_construct_compressed_ = copy_assign_compressed_;
|
||||
}
|
||||
else {
|
||||
copy_construct_ = copy_construct_cb<T>;
|
||||
copy_construct_indices_ = copy_construct_indices_cb<T>;
|
||||
copy_construct_compressed_ = copy_construct_compressed_cb<T>;
|
||||
}
|
||||
}
|
||||
if constexpr (std::is_move_assignable_v<T>) {
|
||||
move_assign_ = move_assign_cb<T>;
|
||||
move_assign_indices_ = move_assign_indices_cb<T>;
|
||||
if constexpr (std::is_trivially_move_assignable_v<T>) {
|
||||
/* This casts away the const from the src pointer. This is fine for trivial types as moving
|
||||
* them does not change the original value. */
|
||||
move_assign_ = reinterpret_cast<decltype(move_assign_)>(copy_assign_);
|
||||
move_assign_indices_ = reinterpret_cast<decltype(move_assign_indices_)>(
|
||||
copy_assign_indices_);
|
||||
}
|
||||
else {
|
||||
move_assign_ = move_assign_cb<T>;
|
||||
move_assign_indices_ = move_assign_indices_cb<T>;
|
||||
}
|
||||
}
|
||||
if constexpr (std::is_move_constructible_v<T>) {
|
||||
move_construct_ = move_construct_cb<T>;
|
||||
move_construct_indices_ = move_construct_indices_cb<T>;
|
||||
if constexpr (std::is_trivially_move_constructible_v<T>) {
|
||||
move_construct_ = move_assign_;
|
||||
move_construct_indices_ = move_assign_indices_;
|
||||
}
|
||||
else {
|
||||
move_construct_ = move_construct_cb<T>;
|
||||
move_construct_indices_ = move_construct_indices_cb<T>;
|
||||
}
|
||||
}
|
||||
if constexpr (std::is_destructible_v<T>) {
|
||||
if constexpr (std::is_move_assignable_v<T>) {
|
||||
relocate_assign_ = relocate_assign_cb<T>;
|
||||
relocate_assign_indices_ = relocate_assign_indices_cb<T>;
|
||||
if constexpr (std::is_trivially_move_assignable_v<T> && std::is_trivially_destructible_v<T>) {
|
||||
relocate_assign_ = move_assign_;
|
||||
relocate_assign_indices_ = move_assign_indices_;
|
||||
|
||||
relocate_construct_ = move_assign_;
|
||||
relocate_construct_indices_ = move_assign_indices_;
|
||||
}
|
||||
if constexpr (std::is_move_constructible_v<T>) {
|
||||
relocate_construct_ = relocate_construct_cb<T>;
|
||||
relocate_construct_indices_ = relocate_construct_indices_cb<T>;
|
||||
else {
|
||||
if constexpr (std::is_move_assignable_v<T>) {
|
||||
relocate_assign_ = relocate_assign_cb<T>;
|
||||
relocate_assign_indices_ = relocate_assign_indices_cb<T>;
|
||||
}
|
||||
if constexpr (std::is_move_constructible_v<T>) {
|
||||
relocate_construct_ = relocate_construct_cb<T>;
|
||||
relocate_construct_indices_ = relocate_construct_indices_cb<T>;
|
||||
}
|
||||
}
|
||||
}
|
||||
if constexpr (std::is_copy_assignable_v<T>) {
|
||||
fill_assign_indices_ = fill_assign_indices_cb<T>;
|
||||
}
|
||||
if constexpr (std::is_copy_constructible_v<T>) {
|
||||
fill_construct_indices_ = fill_construct_indices_cb<T>;
|
||||
if constexpr (std::is_trivially_constructible_v<T>) {
|
||||
fill_construct_indices_ = fill_assign_indices_;
|
||||
}
|
||||
else {
|
||||
fill_construct_indices_ = fill_construct_indices_cb<T>;
|
||||
}
|
||||
}
|
||||
if constexpr ((bool)(Flags & CPPTypeFlags::Hashable)) {
|
||||
hash_ = hash_cb<T>;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue