memory: use initializer list in constructors

for trivial types this is optimized away, non trivial it default
constructs and then assigns it upon construction, minor waste. so lets
use initializer list for these custom types.
This commit is contained in:
Tom Englund 2025-09-26 23:25:52 +02:00 committed by Vaxry
parent 61e295340d
commit 427332a7ca
2 changed files with 5 additions and 10 deletions

View file

@ -28,20 +28,17 @@ namespace Hyprutils {
/* creates a new shared pointer managing a resource /* creates a new shared pointer managing a resource
avoid calling. Could duplicate ownership. Prefer makeShared */ avoid calling. Could duplicate ownership. Prefer makeShared */
explicit CSharedPointer(T* object) noexcept { explicit CSharedPointer(T* object) noexcept : impl_(new Impl_::impl<T>(object)) {
impl_ = new Impl_::impl<T>(object);
increment(); increment();
} }
/* creates a shared pointer from a reference */ /* creates a shared pointer from a reference */
template <typename U, typename = isConstructible<U>> template <typename U, typename = isConstructible<U>>
CSharedPointer(const CSharedPointer<U>& ref) noexcept { CSharedPointer(const CSharedPointer<U>& ref) noexcept : impl_(ref.impl_) {
impl_ = ref.impl_;
increment(); increment();
} }
CSharedPointer(const CSharedPointer& ref) noexcept { CSharedPointer(const CSharedPointer& ref) noexcept : impl_(ref.impl_) {
impl_ = ref.impl_;
increment(); increment();
} }
@ -55,8 +52,7 @@ namespace Hyprutils {
} }
/* allows weakPointer to create from an impl */ /* allows weakPointer to create from an impl */
CSharedPointer(Impl_::impl_base* implementation) noexcept { CSharedPointer(Impl_::impl_base* implementation) noexcept : impl_(implementation) {
impl_ = implementation;
increment(); increment();
} }

View file

@ -22,8 +22,7 @@ namespace Hyprutils {
/* creates a new unique pointer managing a resource /* creates a new unique pointer managing a resource
avoid calling. Could duplicate ownership. Prefer makeUnique */ avoid calling. Could duplicate ownership. Prefer makeUnique */
explicit CUniquePointer(T* object) noexcept { explicit CUniquePointer(T* object) noexcept : impl_(new Impl_::impl<T>(object, false)) {
impl_ = new Impl_::impl<T>(object, false);
increment(); increment();
} }