-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Use unique ptr with default deleter to reduce compile time (#162)
- Loading branch information
1 parent
379e712
commit 3169789
Showing
8 changed files
with
641 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#include "../benchmark.hpp" | ||
#include "ComplexStateMachine.h" | ||
#include "benchmark.hpp" | ||
|
||
using namespace hsm; | ||
|
||
|
23 changes: 23 additions & 0 deletions
23
benchmark/components/fill_unexpected_event_handler_tables_benchmark.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <iostream> | ||
|
||
#include "ComplexStateMachine.h" | ||
|
||
using namespace hsm; | ||
|
||
int main() | ||
{ | ||
auto rootState = state<ComplexStateMachine>; | ||
auto statesMap = make_states_map(rootState); | ||
auto unexpectedEventHandlerTables = make_unexpected_event_handler_tables(rootState); | ||
auto unexpectedEventHandler = [](auto&...) {}; | ||
auto optionalDependency = boost::hana::make_tuple(); | ||
|
||
fill_unexpected_event_handler_tables( | ||
state<ComplexStateMachine>, | ||
statesMap, | ||
unexpectedEventHandlerTables, | ||
unexpectedEventHandler, | ||
optionalDependency); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
|
||
#pragma once | ||
|
||
#include <memory> | ||
|
||
namespace hsm::details::utils { | ||
|
||
template <typename T, typename Delete = std::default_delete<T>> struct dunique_ptr; | ||
|
||
template <typename T> struct dunique_ptr<T, std::default_delete<T>> { | ||
dunique_ptr() | ||
: ptr(nullptr) | ||
{ | ||
} | ||
explicit dunique_ptr(T* ptr) | ||
: ptr(ptr) | ||
{ | ||
} | ||
dunique_ptr(const dunique_ptr&) = delete; | ||
auto operator=(const dunique_ptr&) -> dunique_ptr& = delete; | ||
dunique_ptr(dunique_ptr&& other) noexcept | ||
: ptr(other.ptr) | ||
{ | ||
other.ptr = nullptr; | ||
} | ||
auto operator=(dunique_ptr&& other) noexcept -> dunique_ptr& | ||
{ | ||
swap(other); | ||
return *this; | ||
} | ||
~dunique_ptr() | ||
{ | ||
reset(); | ||
} | ||
void reset(T* value = nullptr) | ||
{ | ||
T* to_delete = ptr; | ||
ptr = value; | ||
// NOLINTNEXTLINE(cppcoreguidelines-owning-memory) | ||
delete to_delete; | ||
} | ||
auto release() -> T* | ||
{ | ||
T* result = ptr; | ||
ptr = nullptr; | ||
return result; | ||
} | ||
explicit operator bool() const | ||
{ | ||
return bool(ptr); | ||
} | ||
[[nodiscard]] auto get() const -> T* | ||
{ | ||
return ptr; | ||
} | ||
auto operator*() const -> T& | ||
{ | ||
return *ptr; | ||
} | ||
auto operator->() const -> T* | ||
{ | ||
return ptr; | ||
} | ||
void swap(dunique_ptr& other) | ||
{ | ||
std::swap(ptr, other.ptr); | ||
} | ||
|
||
auto operator==(const dunique_ptr& other) const -> bool | ||
{ | ||
return ptr == other.ptr; | ||
} | ||
auto operator!=(const dunique_ptr& other) const -> bool | ||
{ | ||
return !(*this == other); | ||
} | ||
auto operator<(const dunique_ptr& other) const -> bool | ||
{ | ||
return ptr < other.ptr; | ||
} | ||
auto operator<=(const dunique_ptr& other) const -> bool | ||
{ | ||
return !(other < *this); | ||
} | ||
auto operator>(const dunique_ptr& other) const -> bool | ||
{ | ||
return other < *this; | ||
} | ||
auto operator>=(const dunique_ptr& other) const -> bool | ||
{ | ||
return !(*this < other); | ||
} | ||
|
||
private: | ||
T* ptr; | ||
}; | ||
|
||
template <typename T, typename D> void swap(dunique_ptr<T, D>& lhs, dunique_ptr<T, D>& rhs) | ||
{ | ||
lhs.swap(rhs); | ||
} | ||
} |
Oops, something went wrong.