Browse Source

perf: utility improvements

master
Dnomd343 4 months ago
parent
commit
a32fad3807
  1. 13
      src/core/utils/utility.h
  2. 7
      src/core/utils/worker.inl

13
src/core/utils/utility.h

@ -43,17 +43,10 @@ consteval int array_sum(const std::array<T, N> &arr) {
/// Calculate offset list of integer array with sizes. /// Calculate offset list of integer array with sizes.
template <typename T, size_t N> template <typename T, size_t N>
requires std::is_integral_v<T> requires std::is_integral_v<T> && (N > 0)
consteval std::array<T, N> to_offset(const std::array<T, N> &arr) { consteval std::array<T, N> to_offset(const std::array<T, N> &arr) {
std::array<T, N> offset; std::array<T, N> offset {};
static_assert(N > 0); std::partial_sum(arr.begin(), arr.end() - 1, offset.begin() + 1);
offset[0] = 0;
T val = 0;
for (int i = 0; i < N - 1; ++i) { // TODO: using `std::views::iota`
val += arr[i];
offset[i + 1] = val;
}
return offset; return offset;
} }

7
src/core/utils/worker.inl

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <atomic> #include <atomic>
#include <memory>
namespace klotski { namespace klotski {
@ -12,14 +13,12 @@ inline void Worker::post(Task &&task) {
} }
inline void Worker::then(Notifier &&after) { inline void Worker::then(Notifier &&after) {
after_ = [after = std::move(after)]() { after_ = std::move(after);
after();
};
} }
inline Worker::~Worker() { inline Worker::~Worker() {
if (tasks_.empty()) { if (tasks_.empty()) {
executor_([after = after_] { executor_([after = std::move(after_)] {
after(); // callback directly after(); // callback directly
}); });
return; return;

Loading…
Cancel
Save