From a2c50744da2cc590d01bb9155681d417359c80f5 Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Sun, 11 Apr 2021 18:56:08 +0200 Subject: [PATCH] remove public state::destroy() --- include/cubescript/cubescript/state.hh | 16 +++------------- src/cs_state.cc | 26 +++++++++++++++++++++----- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/include/cubescript/cubescript/state.hh b/include/cubescript/cubescript/state.hh index d021c7f..4ade466 100644 --- a/include/cubescript/cubescript/state.hh +++ b/include/cubescript/cubescript/state.hh @@ -38,22 +38,12 @@ struct LIBCUBESCRIPT_EXPORT state { virtual ~state(); state(state const &) = delete; - state(state &&s) { - swap(s); - } + state(state &&s); state &operator=(state const &) = delete; - state &operator=(state &&s) { - swap(s); - s.destroy(); - return *this; - } + state &operator=(state &&s); - void destroy(); - - void swap(state &s) { - std::swap(p_tstate, s.p_tstate); - } + void swap(state &s); state new_thread(); diff --git a/src/cs_state.cc b/src/cs_state.cc index d83a9bc..de613a6 100644 --- a/src/cs_state.cc +++ b/src/cs_state.cc @@ -266,18 +266,34 @@ state::state(alloc_func func, void *data) { init_lib_base(*this); } -LIBCUBESCRIPT_EXPORT state::~state() { - destroy(); -} -LIBCUBESCRIPT_EXPORT void state::destroy() { + +LIBCUBESCRIPT_EXPORT state::~state() { if (!p_tstate || !p_tstate->owner) { return; } auto *sp = p_tstate->istate; sp->destroy(p_tstate); sp->destroy(sp); - p_tstate = nullptr; +} + +LIBCUBESCRIPT_EXPORT state::state(state &&s) { + swap(s); +} + +LIBCUBESCRIPT_EXPORT state &state::operator=(state &&s) { + if (p_tstate && p_tstate->owner) { + auto *sp = p_tstate->istate; + sp->destroy(p_tstate); + sp->destroy(sp); + } + p_tstate = s.p_tstate; + s.p_tstate = nullptr; + return *this; +} + +LIBCUBESCRIPT_EXPORT void state::swap(state &s) { + std::swap(p_tstate, s.p_tstate); } state::state(void *is) {