Work on performance improvements
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -5,11 +5,7 @@
|
||||
|
||||
extern "C" {
|
||||
TypeClass GetEvalValueTypeClass(EvalValue* v){
|
||||
return v->GetType().get()->GetClass();
|
||||
}
|
||||
|
||||
ScriptType* GetEvalValueType(EvalValue* v){
|
||||
return v->GetType().get();
|
||||
return v->GetTypeClass();
|
||||
}
|
||||
|
||||
int64_t EvaluateEvalValueInteger(EvalValue* v){
|
||||
|
||||
@@ -12,7 +12,7 @@ class EvalValue{
|
||||
public:
|
||||
EvalValue() = default;
|
||||
virtual ~EvalValue() = default;
|
||||
virtual std::shared_ptr<ScriptType> GetType() = 0;
|
||||
virtual const TypeClass GetTypeClass() = 0;
|
||||
|
||||
virtual bool operator ==(EvalValue* b) = 0;
|
||||
|
||||
@@ -43,28 +43,27 @@ public:
|
||||
};
|
||||
|
||||
class BooleanEvalValue : public EvalValue{
|
||||
bool _value;
|
||||
std::shared_ptr<ScriptType> _type;
|
||||
const bool _value;
|
||||
public:
|
||||
explicit BooleanEvalValue(bool val){
|
||||
_value = val;
|
||||
_type = std::make_shared<ScriptType>(TypeClass::Bool);
|
||||
explicit BooleanEvalValue(bool val)
|
||||
: _value(val)
|
||||
{
|
||||
}
|
||||
|
||||
shared_ptr<EvalValue> Clone() final{
|
||||
return make_shared<BooleanEvalValue>(_value);
|
||||
}
|
||||
|
||||
std::shared_ptr<ScriptType> GetType() final{
|
||||
return _type;
|
||||
};
|
||||
const TypeClass GetTypeClass() final{
|
||||
return TypeClass ::Bool;
|
||||
}
|
||||
|
||||
bool EvaluateBool() final{
|
||||
return _value;
|
||||
}
|
||||
|
||||
bool operator ==(EvalValue* b) final{
|
||||
if (b->GetType()->GetClass() != TypeClass::Bool)
|
||||
if (b->GetTypeClass() != TypeClass::Bool)
|
||||
return false;
|
||||
return this->EvaluateBool() == b->EvaluateBool();
|
||||
};
|
||||
|
||||
@@ -66,7 +66,7 @@ NumericEvalValue *NumericEvalValue::operator/(NumericEvalValue *b) {
|
||||
}
|
||||
|
||||
bool NumericEvalValue::operator==(EvalValue *b) {
|
||||
if (b->GetType()->GetClass() != TypeClass::Number)
|
||||
if (b->GetTypeClass() != TypeClass::Number)
|
||||
return false;
|
||||
auto numVal = (NumericEvalValue*)b;
|
||||
if (this->IsFloat() != numVal->IsFloat())
|
||||
|
||||
@@ -10,12 +10,11 @@ class NumericEvalValue : public EvalValue{
|
||||
virtual long GetIntegerValue() = 0;
|
||||
virtual double GetFloatValue() = 0;
|
||||
|
||||
protected:
|
||||
std::shared_ptr<ScriptType> _type;
|
||||
public:
|
||||
virtual const bool IsFloat() = 0;
|
||||
std::shared_ptr<ScriptType> GetType() override {
|
||||
return _type;
|
||||
|
||||
const TypeClass GetTypeClass() final{
|
||||
return TypeClass ::Number;
|
||||
}
|
||||
|
||||
NumericEvalValue* operator +(NumericEvalValue* b);
|
||||
@@ -35,7 +34,6 @@ class IntegerEvalValue : public NumericEvalValue{
|
||||
double GetFloatValue() final{ throw EvaluationException("Attempting to retrieve float from int eval value."); }
|
||||
public:
|
||||
explicit IntegerEvalValue(long value){
|
||||
_type = std::make_shared<NumericScriptType>(true, false);
|
||||
_value = value;
|
||||
}
|
||||
const bool IsFloat() final{
|
||||
@@ -61,7 +59,6 @@ class FloatEvalValue : public NumericEvalValue{
|
||||
double GetFloatValue() final{return _value;}
|
||||
public:
|
||||
explicit FloatEvalValue(double value){
|
||||
_type = std::make_shared<NumericScriptType>(true, true);
|
||||
_value = value;
|
||||
}
|
||||
const bool IsFloat() final{
|
||||
|
||||
@@ -38,17 +38,21 @@ public:
|
||||
_hash = rand();
|
||||
}
|
||||
|
||||
std::shared_ptr<ScriptType> GetType() final{
|
||||
std::shared_ptr<ScriptType> GetType(){
|
||||
return _type;
|
||||
}
|
||||
|
||||
const TypeClass GetTypeClass() final{
|
||||
return TypeClass ::Function;
|
||||
}
|
||||
|
||||
shared_ptr<EvalValue> Clone() final{
|
||||
return shared_ptr<ScriptFunctionEvalValue>(new ScriptFunctionEvalValue(_innerBlock, _scope, _type, _hash));
|
||||
}
|
||||
|
||||
|
||||
bool operator ==(EvalValue* b) final{
|
||||
if (b->GetType()->GetClass() != TypeClass::Function)
|
||||
if (b->GetTypeClass() != TypeClass::Function)
|
||||
return false;
|
||||
return this->_hash == ((ScriptFunctionEvalValue*)b)->_hash;
|
||||
};
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
|
||||
#include "StringEvalValue.hpp"
|
||||
@@ -11,19 +11,18 @@ using namespace std;
|
||||
class StringEvalValue : public EvalValue{
|
||||
string _value;
|
||||
size_t _hash;
|
||||
std::shared_ptr<ScriptType> _type;
|
||||
public:
|
||||
explicit StringEvalValue(string s){
|
||||
_value = move(s);
|
||||
_hash = HashedString::ConstHash (_value.c_str());
|
||||
_type = std::make_shared<StringScriptType>(true, _hash);
|
||||
}
|
||||
|
||||
std::shared_ptr<ScriptType> GetType() final{
|
||||
return _type;
|
||||
};
|
||||
const TypeClass GetTypeClass() final{
|
||||
return TypeClass ::String;
|
||||
}
|
||||
|
||||
bool operator ==(EvalValue* b) final{
|
||||
if (b->GetType()->GetClass() != TypeClass::String)
|
||||
if (b->GetTypeClass() != TypeClass::String)
|
||||
return false;
|
||||
return this->_hash == b->GetHashCode();
|
||||
};
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
|
||||
#include "TableEvalValue.hpp"
|
||||
@@ -8,23 +8,20 @@ using namespace std;
|
||||
|
||||
class TableEvalValue : public EvalValue {
|
||||
shared_ptr<unordered_map<size_t, shared_ptr<EvalValue>>> _table;
|
||||
shared_ptr<ScriptType> _type;
|
||||
size_t _hash;
|
||||
|
||||
explicit TableEvalValue(shared_ptr<unordered_map<size_t, shared_ptr<EvalValue>>> table, shared_ptr<ScriptType> type, size_t hash){
|
||||
explicit TableEvalValue(shared_ptr<unordered_map<size_t, shared_ptr<EvalValue>>> table, size_t hash){
|
||||
_table = std::move(table);
|
||||
_type = std::move(type);
|
||||
_hash = hash;
|
||||
}
|
||||
public:
|
||||
explicit TableEvalValue(shared_ptr<unordered_map<size_t, shared_ptr<EvalValue>>> table, shared_ptr<ScriptType> type){
|
||||
explicit TableEvalValue(shared_ptr<unordered_map<size_t, shared_ptr<EvalValue>>> table){
|
||||
_table = std::move(table);
|
||||
_type = std::move(type);
|
||||
_hash = rand();
|
||||
}
|
||||
|
||||
std::shared_ptr<ScriptType> GetType() final{
|
||||
return _type;
|
||||
const TypeClass GetTypeClass() final{
|
||||
return TypeClass ::Table;
|
||||
}
|
||||
|
||||
size_t GetHashCode() final{
|
||||
@@ -36,7 +33,7 @@ public:
|
||||
}
|
||||
|
||||
shared_ptr<EvalValue> Clone() final{
|
||||
return shared_ptr<EvalValue>(new TableEvalValue(_table, _type, _hash));
|
||||
return shared_ptr<EvalValue>(new TableEvalValue(_table, _hash));
|
||||
}
|
||||
|
||||
shared_ptr<EvalValue> IndexValue(EvalValue* val) final{
|
||||
|
||||
Reference in New Issue
Block a user