Skip to content

Commit

Permalink
[Misc] Fix Vector::emplace_at assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
native-m committed Oct 19, 2024
1 parent 8ca302b commit c346d64
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/core/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,19 +163,20 @@ struct Vector {
return *item;
}

// Shift element by 1
T* begin_ptr = intern_.data + intern_.size - 1;
T* dst_ptr = begin_ptr + 1;
T* end_ptr = intern_.data + idx;
while (begin_ptr >= end_ptr) {
if constexpr (std::movable<T>) {
if constexpr (std::is_move_assignable_v<T>) {
*dst_ptr-- = std::move(*begin_ptr);
} else if constexpr (std::copyable<T>) {
} else if constexpr (std::is_copy_assignable_v<T>) {
*dst_ptr-- = *begin_ptr;
}
begin_ptr--;
}

if (!std::is_trivially_destructible_v<T>) {
if constexpr (!std::is_trivially_destructible_v<T>) {
(intern_.data + idx)->~T();
}

Expand Down Expand Up @@ -209,7 +210,7 @@ struct Vector {
inline void push_front(T&& item)
requires std::move_constructible<T>
{
emplace_at(0, item);
emplace_at(0, std::forward<T>(item));
}

inline void push_back(const T& item)
Expand Down
1 change: 1 addition & 0 deletions src/engine/assets_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ void SampleTable::destroy_sample(uint64_t hash) {
}

void SampleTable::shutdown() {
// NOTE(native-m): Sample may leak if created with ref_count == 0
for (auto& [hash, sample] : samples) {
Log::debug("Sample asset leak: {}", sample.ref_count);
}
Expand Down

0 comments on commit c346d64

Please sign in to comment.