mirror of
https://github.com/hyprwm/hyprutils.git
synced 2025-12-20 09:20:08 +01:00
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:
parent
61e295340d
commit
427332a7ca
2 changed files with 5 additions and 10 deletions
|
|
@ -28,20 +28,17 @@ namespace Hyprutils {
|
|||
|
||||
/* creates a new shared pointer managing a resource
|
||||
avoid calling. Could duplicate ownership. Prefer makeShared */
|
||||
explicit CSharedPointer(T* object) noexcept {
|
||||
impl_ = new Impl_::impl<T>(object);
|
||||
explicit CSharedPointer(T* object) noexcept : impl_(new Impl_::impl<T>(object)) {
|
||||
increment();
|
||||
}
|
||||
|
||||
/* creates a shared pointer from a reference */
|
||||
template <typename U, typename = isConstructible<U>>
|
||||
CSharedPointer(const CSharedPointer<U>& ref) noexcept {
|
||||
impl_ = ref.impl_;
|
||||
CSharedPointer(const CSharedPointer<U>& ref) noexcept : impl_(ref.impl_) {
|
||||
increment();
|
||||
}
|
||||
|
||||
CSharedPointer(const CSharedPointer& ref) noexcept {
|
||||
impl_ = ref.impl_;
|
||||
CSharedPointer(const CSharedPointer& ref) noexcept : impl_(ref.impl_) {
|
||||
increment();
|
||||
}
|
||||
|
||||
|
|
@ -55,8 +52,7 @@ namespace Hyprutils {
|
|||
}
|
||||
|
||||
/* allows weakPointer to create from an impl */
|
||||
CSharedPointer(Impl_::impl_base* implementation) noexcept {
|
||||
impl_ = implementation;
|
||||
CSharedPointer(Impl_::impl_base* implementation) noexcept : impl_(implementation) {
|
||||
increment();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,8 +22,7 @@ namespace Hyprutils {
|
|||
|
||||
/* creates a new unique pointer managing a resource
|
||||
avoid calling. Could duplicate ownership. Prefer makeUnique */
|
||||
explicit CUniquePointer(T* object) noexcept {
|
||||
impl_ = new Impl_::impl<T>(object, false);
|
||||
explicit CUniquePointer(T* object) noexcept : impl_(new Impl_::impl<T>(object, false)) {
|
||||
increment();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue