Rework of memory handling in Evaluation
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -5,26 +5,23 @@
|
||||
#include <utility>
|
||||
#include <map>
|
||||
#include "EvalValue.hpp"
|
||||
#include "../EvalValuePointer.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Porygon::Evaluation {
|
||||
class NumericalTableEvalValue : public EvalValue {
|
||||
const shared_ptr<vector<shared_ptr<const EvalValue>>> _table;
|
||||
const shared_ptr<vector<EvalValuePointer>> _table;
|
||||
const size_t _hash;
|
||||
|
||||
explicit NumericalTableEvalValue(shared_ptr<vector<shared_ptr<const EvalValue>>> table, size_t hash)
|
||||
explicit NumericalTableEvalValue(shared_ptr<vector<EvalValuePointer>> table, size_t hash)
|
||||
: _table(std::move(table)),
|
||||
_hash(hash)
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
explicit NumericalTableEvalValue(shared_ptr<vector<shared_ptr<const EvalValue>>> table) :
|
||||
_table(std::move(table)),
|
||||
_hash(rand())
|
||||
{
|
||||
}
|
||||
explicit NumericalTableEvalValue(shared_ptr<vector<EvalValuePointer>> table);
|
||||
|
||||
[[nodiscard]]
|
||||
inline TypeClass GetTypeClass() const final {
|
||||
@@ -42,22 +39,22 @@ namespace Porygon::Evaluation {
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline shared_ptr<const EvalValue> Clone() const final {
|
||||
return shared_ptr<EvalValue>(new NumericalTableEvalValue(_table, _hash));
|
||||
inline EvalValue* Clone() const final {
|
||||
return new NumericalTableEvalValue(_table, _hash);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline shared_ptr<const EvalValue> IndexValue(const EvalValue *val) const final {
|
||||
inline const EvalValue* IndexValue(const EvalValue *val) const final {
|
||||
const auto index = val->EvaluateInteger() - 1;
|
||||
return this->_table->at(index);
|
||||
return this->_table->at(index).Clone();
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline shared_ptr<const EvalValue> IndexValue(uint32_t hash) const final {
|
||||
return this->_table->at(hash - 1);
|
||||
inline EvalValue* IndexValue(uint32_t hash) const final {
|
||||
return this->_table->at(hash - 1)-> Clone();
|
||||
}
|
||||
|
||||
inline void SetIndexValue(const EvalValue *key, const shared_ptr<const EvalValue> &value) const final {
|
||||
inline void SetIndexValue(const EvalValue *key, const EvalValue* value) const final {
|
||||
auto index = key->EvaluateInteger();
|
||||
this->_table->at(index - 1) = value;
|
||||
}
|
||||
@@ -66,7 +63,7 @@ namespace Porygon::Evaluation {
|
||||
Iterator * GetKeyIterator() const final;
|
||||
|
||||
[[nodiscard]]
|
||||
inline shared_ptr<vector<shared_ptr<const EvalValue>>> GetTable() const{
|
||||
inline shared_ptr<vector<EvalValuePointer>> GetTable() const{
|
||||
return _table;
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user