diff options
author | Jacques Lucke <jacques@blender.org> | 2020-07-05 16:08:26 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-07-05 16:08:26 +0300 |
commit | 247a28f242c2c0a8931a84df0db6e60763642f30 (patch) | |
tree | cdd5721ab333967a5b4e0489ded5f29bf48610b4 /source/blender/blenlib/BLI_map_slots.hh | |
parent | 5d79f9f276b4b3e6289308c534c58e7ee3bb5e2d (diff) |
Revert "BLI: refactor how buffers for small object optimization are stored"
This reverts commit 5d79f9f276b4b3e6289308c534c58e7ee3bb5e2d.
This was introducing build errors in windows. Need a bit more time to check it.
Diffstat (limited to 'source/blender/blenlib/BLI_map_slots.hh')
-rw-r--r-- | source/blender/blenlib/BLI_map_slots.hh | 66 |
1 files changed, 33 insertions, 33 deletions
diff --git a/source/blender/blenlib/BLI_map_slots.hh b/source/blender/blenlib/BLI_map_slots.hh index 9c7f671b8b4..c3d88205e0a 100644 --- a/source/blender/blenlib/BLI_map_slots.hh +++ b/source/blender/blenlib/BLI_map_slots.hh @@ -53,8 +53,8 @@ template<typename Key, typename Value> class SimpleMapSlot { }; State state_; - TypedBuffer<Key> key_buffer_; - TypedBuffer<Value> value_buffer_; + AlignedBuffer<sizeof(Key), alignof(Key)> key_buffer_; + AlignedBuffer<sizeof(Value), alignof(Value)> value_buffer_; public: /** @@ -71,8 +71,8 @@ template<typename Key, typename Value> class SimpleMapSlot { ~SimpleMapSlot() { if (state_ == Occupied) { - key_buffer_->~Key(); - value_buffer_->~Value(); + this->key()->~Key(); + this->value()->~Value(); } } @@ -84,8 +84,8 @@ template<typename Key, typename Value> class SimpleMapSlot { { state_ = other.state_; if (other.state_ == Occupied) { - new (&key_buffer_) Key(*other.key_buffer_); - new (&value_buffer_) Value(*other.value_buffer_); + new ((void *)this->key()) Key(*other.key()); + new ((void *)this->value()) Value(*other.value()); } } @@ -98,8 +98,8 @@ template<typename Key, typename Value> class SimpleMapSlot { { state_ = other.state_; if (other.state_ == Occupied) { - new (&key_buffer_) Key(std::move(*other.key_buffer_)); - new (&value_buffer_) Value(std::move(*other.value_buffer_)); + new ((void *)this->key()) Key(std::move(*other.key())); + new ((void *)this->value()) Value(std::move(*other.value())); } } @@ -108,7 +108,7 @@ template<typename Key, typename Value> class SimpleMapSlot { */ Key *key() { - return key_buffer_; + return (Key *)key_buffer_.ptr(); } /** @@ -116,7 +116,7 @@ template<typename Key, typename Value> class SimpleMapSlot { */ const Key *key() const { - return key_buffer_; + return (const Key *)key_buffer_.ptr(); } /** @@ -124,7 +124,7 @@ template<typename Key, typename Value> class SimpleMapSlot { */ Value *value() { - return value_buffer_; + return (Value *)value_buffer_.ptr(); } /** @@ -132,7 +132,7 @@ template<typename Key, typename Value> class SimpleMapSlot { */ const Value *value() const { - return value_buffer_; + return (const Value *)value_buffer_.ptr(); } /** @@ -158,7 +158,7 @@ template<typename Key, typename Value> class SimpleMapSlot { template<typename Hash> uint32_t get_hash(const Hash &hash) { BLI_assert(this->is_occupied()); - return hash(*key_buffer_); + return hash(*this->key()); } /** @@ -170,10 +170,10 @@ template<typename Key, typename Value> class SimpleMapSlot { BLI_assert(!this->is_occupied()); BLI_assert(other.is_occupied()); state_ = Occupied; - new (&key_buffer_) Key(std::move(*other.key_buffer_)); - new (&value_buffer_) Value(std::move(*other.value_buffer_)); - other.key_buffer_->~Key(); - other.value_buffer_->~Value(); + new ((void *)this->key()) Key(std::move(*other.key())); + new ((void *)this->value()) Value(std::move(*other.value())); + other.key()->~Key(); + other.value()->~Value(); } /** @@ -184,7 +184,7 @@ template<typename Key, typename Value> class SimpleMapSlot { bool contains(const ForwardKey &key, const IsEqual &is_equal, uint32_t UNUSED(hash)) const { if (state_ == Occupied) { - return is_equal(key, *key_buffer_); + return is_equal(key, *this->key()); } return false; } @@ -198,7 +198,7 @@ template<typename Key, typename Value> class SimpleMapSlot { { BLI_assert(!this->is_occupied()); this->occupy_without_value(std::forward<ForwardKey>(key), hash); - new (&value_buffer_) Value(std::forward<ForwardValue>(value)); + new ((void *)this->value()) Value(std::forward<ForwardValue>(value)); } /** @@ -209,7 +209,7 @@ template<typename Key, typename Value> class SimpleMapSlot { { BLI_assert(!this->is_occupied()); state_ = Occupied; - new (&key_buffer_) Key(std::forward<ForwardKey>(key)); + new ((void *)this->key()) Key(std::forward<ForwardKey>(key)); } /** @@ -220,8 +220,8 @@ template<typename Key, typename Value> class SimpleMapSlot { { BLI_assert(this->is_occupied()); state_ = Removed; - key_buffer_->~Key(); - value_buffer_->~Value(); + this->key()->~Key(); + this->value()->~Value(); } }; @@ -236,7 +236,7 @@ template<typename Key, typename Value> class SimpleMapSlot { template<typename Key, typename Value, typename KeyInfo> class IntrusiveMapSlot { private: Key key_ = KeyInfo::get_empty(); - TypedBuffer<Value> value_buffer_; + AlignedBuffer<sizeof(Value), alignof(Value)> value_buffer_; public: IntrusiveMapSlot() = default; @@ -244,21 +244,21 @@ template<typename Key, typename Value, typename KeyInfo> class IntrusiveMapSlot ~IntrusiveMapSlot() { if (KeyInfo::is_not_empty_or_removed(key_)) { - value_buffer_->~Value(); + this->value()->~Value(); } } IntrusiveMapSlot(const IntrusiveMapSlot &other) : key_(other.key_) { if (KeyInfo::is_not_empty_or_removed(key_)) { - new (&value_buffer_) Value(*other.value_buffer_); + new ((void *)this->value()) Value(*other.value()); } } IntrusiveMapSlot(IntrusiveMapSlot &&other) noexcept : key_(other.key_) { if (KeyInfo::is_not_empty_or_removed(key_)) { - new (&value_buffer_) Value(std::move(*other.value_buffer_)); + new ((void *)this->value()) Value(std::move(*other.value())); } } @@ -274,12 +274,12 @@ template<typename Key, typename Value, typename KeyInfo> class IntrusiveMapSlot Value *value() { - return value_buffer_; + return (Value *)value_buffer_.ptr(); } const Value *value() const { - return value_buffer_; + return (const Value *)value_buffer_.ptr(); } bool is_occupied() const @@ -295,7 +295,7 @@ template<typename Key, typename Value, typename KeyInfo> class IntrusiveMapSlot template<typename Hash> uint32_t get_hash(const Hash &hash) { BLI_assert(this->is_occupied()); - return hash(key_); + return hash(*this->key()); } void relocate_occupied_here(IntrusiveMapSlot &other, uint32_t UNUSED(hash)) @@ -303,9 +303,9 @@ template<typename Key, typename Value, typename KeyInfo> class IntrusiveMapSlot BLI_assert(!this->is_occupied()); BLI_assert(other.is_occupied()); key_ = std::move(other.key_); - new (&value_buffer_) Value(std::move(*other.value_buffer_)); + new ((void *)this->value()) Value(std::move(*other.value())); other.key_.~Key(); - other.value_buffer_->~Value(); + other.value()->~Value(); } template<typename ForwardKey, typename IsEqual> @@ -321,7 +321,7 @@ template<typename Key, typename Value, typename KeyInfo> class IntrusiveMapSlot BLI_assert(!this->is_occupied()); BLI_assert(KeyInfo::is_not_empty_or_removed(key)); this->occupy_without_value(std::forward<ForwardKey>(key), hash); - new (&value_buffer_) Value(std::forward<ForwardValue>(value)); + new ((void *)this->value()) Value(std::forward<ForwardValue>(value)); } template<typename ForwardKey> void occupy_without_value(ForwardKey &&key, uint32_t UNUSED(hash)) @@ -335,7 +335,7 @@ template<typename Key, typename Value, typename KeyInfo> class IntrusiveMapSlot { BLI_assert(this->is_occupied()); KeyInfo::remove(key_); - value_buffer_->~Value(); + this->value()->~Value(); } }; |