Improved performance when binding by reusing many common scripttype objects
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:
@@ -10,10 +10,10 @@
|
||||
namespace Porygon {
|
||||
class GenericFunctionOption{
|
||||
shared_ptr<const ScriptType> _returnType;
|
||||
vector<shared_ptr<ScriptType>> _parameterTypes;
|
||||
vector<shared_ptr<const ScriptType>> _parameterTypes;
|
||||
size_t _option = 0;
|
||||
public:
|
||||
GenericFunctionOption(shared_ptr<ScriptType> returnType, vector<shared_ptr<ScriptType>> parameterTypes)
|
||||
GenericFunctionOption(shared_ptr<const ScriptType> returnType, vector<shared_ptr<const ScriptType>> parameterTypes)
|
||||
: _returnType(std::move(returnType)), _parameterTypes(std::move(parameterTypes)){
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace Porygon {
|
||||
_returnType = t;
|
||||
}
|
||||
|
||||
[[nodiscard]] inline vector<shared_ptr<ScriptType>> GetParameterTypes() const {
|
||||
[[nodiscard]] inline vector<shared_ptr<const ScriptType>> GetParameterTypes() const {
|
||||
return _parameterTypes;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace Porygon {
|
||||
continue;
|
||||
auto parameter = parameters->at(i);
|
||||
const auto& parameterType = parameter->GetType();
|
||||
if (parameterType->operator!=(_parameterTypes[i].get())){
|
||||
if (parameterType->operator!=(_parameterTypes[i])){
|
||||
auto castResult = parameterType->CastableTo(_parameterTypes[i], false);
|
||||
if (castResult == CastResult::InvalidCast){
|
||||
return false;
|
||||
@@ -125,7 +125,7 @@ namespace Porygon {
|
||||
class ScriptFunctionOption : public GenericFunctionOption {
|
||||
vector<shared_ptr<const Porygon::Binder::BoundVariableKey>> _parameterKeys;
|
||||
public:
|
||||
ScriptFunctionOption(shared_ptr<ScriptType> returnType, vector<shared_ptr<ScriptType>> parameterTypes,
|
||||
ScriptFunctionOption(shared_ptr<const ScriptType> returnType, vector<shared_ptr<const ScriptType>> parameterTypes,
|
||||
vector<shared_ptr<const Porygon::Binder::BoundVariableKey>> parameterKeys)
|
||||
: GenericFunctionOption(move(returnType), std::move(parameterTypes)), _parameterKeys(move(parameterKeys)) {
|
||||
}
|
||||
|
||||
@@ -6,10 +6,14 @@ namespace Porygon{
|
||||
return false;
|
||||
}
|
||||
|
||||
shared_ptr<const ScriptType> ScriptType::BoolType = make_shared<ScriptType>(TypeClass::Bool);
|
||||
shared_ptr<const ScriptType> ScriptType::NilType = make_shared<ScriptType>(TypeClass::Nil);
|
||||
shared_ptr<const NumericScriptType> NumericScriptType::AwareInt = make_shared<NumericScriptType>(true, false);
|
||||
shared_ptr<const NumericScriptType> NumericScriptType::AwareFloat = make_shared<NumericScriptType>(true, true);
|
||||
shared_ptr<const NumericScriptType> NumericScriptType::Unaware = make_shared<NumericScriptType>(false, false);
|
||||
shared_ptr<const StringScriptType> StringScriptType::Dynamic = make_shared<StringScriptType>(false, 0);
|
||||
|
||||
shared_ptr<const ScriptType> ScriptType::GetIndexedType(const ScriptType*) const{
|
||||
if (_class == TypeClass::String){
|
||||
return make_shared<ScriptType>(TypeClass::String);
|
||||
}
|
||||
return make_shared<ScriptType>(TypeClass::Error);
|
||||
}
|
||||
|
||||
@@ -18,8 +22,13 @@ namespace Porygon{
|
||||
return new ScriptType(t);
|
||||
}
|
||||
|
||||
ScriptType* CreateNumericScriptType(bool isAware, bool isFloat){
|
||||
return new NumericScriptType(isAware, isFloat);
|
||||
const ScriptType* CreateNumericScriptType(bool isAware, bool isFloat){
|
||||
if (isAware){
|
||||
if (isFloat)
|
||||
return NumericScriptType::AwareFloat.get();
|
||||
return NumericScriptType::AwareInt.get();
|
||||
}
|
||||
return NumericScriptType::Unaware.get();
|
||||
}
|
||||
|
||||
ScriptType* CreateStringScriptType(bool knownAtBind, uint32_t hash){
|
||||
@@ -27,11 +36,11 @@ namespace Porygon{
|
||||
}
|
||||
|
||||
ScriptType* CreateUserDataFunctionScriptType(ScriptType* returnType, ScriptType* parameters[], size_t parameterCount){
|
||||
vector<shared_ptr<ScriptType>> vector(parameterCount);
|
||||
for (int i = 0; i < parameterCount; i++){
|
||||
vector[i] = shared_ptr<ScriptType>(parameters[i]);
|
||||
vector<shared_ptr<const ScriptType>> vector(parameterCount);
|
||||
for (size_t i = 0; i < parameterCount; i++){
|
||||
vector[i] = shared_ptr<const ScriptType>(parameters[i]);
|
||||
}
|
||||
auto option = new UserData::UserDataFunctionOption(shared_ptr<ScriptType>(returnType), vector);
|
||||
auto option = new UserData::UserDataFunctionOption(shared_ptr<const ScriptType>(returnType), vector);
|
||||
auto type = new GenericFunctionScriptType();
|
||||
type->RegisterFunctionOption(option);
|
||||
return type;
|
||||
|
||||
@@ -33,24 +33,19 @@ namespace Porygon{
|
||||
_class = c;
|
||||
}
|
||||
|
||||
static shared_ptr<const ScriptType> BoolType;
|
||||
static shared_ptr<const ScriptType> NilType;
|
||||
virtual ~ScriptType() = default;
|
||||
|
||||
[[nodiscard]] inline TypeClass GetClass() const{
|
||||
return _class;
|
||||
}
|
||||
|
||||
virtual bool operator ==(const ScriptType& b) const{
|
||||
return _class == b._class;
|
||||
};
|
||||
|
||||
virtual bool operator ==(const ScriptType* b) const{
|
||||
virtual bool operator ==(const shared_ptr<const ScriptType>& b) const{
|
||||
return _class == b->_class;
|
||||
};
|
||||
|
||||
virtual bool operator !=(const ScriptType& b) const{
|
||||
return ! (operator==(b));
|
||||
}
|
||||
virtual bool operator !=(const ScriptType* b) const{
|
||||
|
||||
virtual bool operator !=(const shared_ptr<const ScriptType>& b) const{
|
||||
return ! (operator==(b));
|
||||
}
|
||||
|
||||
@@ -88,7 +83,20 @@ namespace Porygon{
|
||||
bool _awareOfFloat;
|
||||
// Is this value a float?
|
||||
bool _isFloat;
|
||||
|
||||
public:
|
||||
static shared_ptr<const NumericScriptType> AwareInt;
|
||||
static shared_ptr<const NumericScriptType> AwareFloat;
|
||||
static shared_ptr<const NumericScriptType> Unaware;
|
||||
|
||||
static shared_ptr<const NumericScriptType> ResolveType(bool isAware, bool isFloat){
|
||||
if (isAware){
|
||||
if (isFloat) return AwareFloat;
|
||||
return AwareInt;
|
||||
}
|
||||
return Unaware;
|
||||
}
|
||||
|
||||
explicit NumericScriptType(bool floatAware, bool isFloat) : ScriptType(TypeClass::Number){
|
||||
_awareOfFloat = floatAware;
|
||||
_isFloat = isFloat;
|
||||
@@ -102,22 +110,19 @@ namespace Porygon{
|
||||
return _isFloat;
|
||||
}
|
||||
|
||||
bool operator ==(const ScriptType& b) const final{
|
||||
if (b.GetClass() != TypeClass::Number)
|
||||
bool operator ==(const shared_ptr<const ScriptType>& b) const final{
|
||||
if (b->GetClass() != TypeClass::Number)
|
||||
return false;
|
||||
auto bNum = dynamic_cast<const NumericScriptType&>(b);
|
||||
if (bNum.IsAwareOfFloat() && IsAwareOfFloat()){
|
||||
return bNum.IsFloat() == IsFloat();
|
||||
auto bNum = dynamic_pointer_cast<const NumericScriptType>(b);
|
||||
if (bNum->IsAwareOfFloat() && IsAwareOfFloat()){
|
||||
return bNum->IsFloat() == IsFloat();
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
bool operator !=(const ScriptType& b) const final{
|
||||
bool operator !=(const shared_ptr<const ScriptType>& b) const final{
|
||||
return ! (operator==(b));
|
||||
}
|
||||
bool operator !=(const ScriptType* b) const final{
|
||||
return ! (operator==(*b));
|
||||
}
|
||||
|
||||
[[nodiscard]] CastResult CastableTo(const shared_ptr<const ScriptType>& castType, bool explicitCast) const final{
|
||||
if (!explicitCast){
|
||||
@@ -140,6 +145,8 @@ namespace Porygon{
|
||||
_hashValue = hashValue;
|
||||
}
|
||||
|
||||
static shared_ptr<const StringScriptType> Dynamic;
|
||||
|
||||
[[nodiscard]]
|
||||
bool CanBeIndexedWith(const ScriptType* indexer) const final{
|
||||
if (indexer -> GetClass() != TypeClass::Number)
|
||||
@@ -149,7 +156,7 @@ namespace Porygon{
|
||||
}
|
||||
|
||||
inline shared_ptr<const ScriptType> GetIndexedType(const ScriptType* indexer) const final{
|
||||
return make_shared<StringScriptType>(false, 0);
|
||||
return StringScriptType::Dynamic;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
@@ -188,7 +195,7 @@ namespace Porygon{
|
||||
}
|
||||
[[nodiscard]]
|
||||
inline shared_ptr<const ScriptType> GetIteratorKeyType() const final{
|
||||
return make_shared<NumericScriptType>(true, false);
|
||||
return NumericScriptType::AwareInt;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user