Improved performance when binding by reusing many common scripttype objects
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2019-09-01 15:35:45 +02:00
parent 79873d9d6a
commit a3e77f650a
14 changed files with 141 additions and 113 deletions

View File

@@ -24,11 +24,16 @@ namespace Porygon::UserData {
return make_shared<UserDataCollectionType>(keyType, valueType, true, true);
}
static UserDataCollectionType* CreateIndexable(const ScriptType* keyType, const ScriptType* valueType){
return new UserDataCollectionType(shared_ptr<const ScriptType>(keyType),
static shared_ptr<UserDataCollectionType> CreateIndexable(const ScriptType* keyType, const ScriptType* valueType){
return make_shared<UserDataCollectionType>(shared_ptr<const ScriptType>(keyType),
shared_ptr<const ScriptType>(valueType), true, true);
}
static UserDataCollectionType* CreateIndexableExtern(const ScriptType* keyType, const ScriptType* valueType){
return new UserDataCollectionType(shared_ptr<const ScriptType>(keyType),
shared_ptr<const ScriptType>(valueType), true, true);
}
static shared_ptr<UserDataCollectionType> CreateIterable(const shared_ptr<const ScriptType>& valueType){
return make_shared<UserDataCollectionType>(nullptr, valueType, false, true);
}
@@ -42,7 +47,7 @@ namespace Porygon::UserData {
if (!_indexable){
return false;
}
return indexer->operator==(_keyType.get());
return indexer->operator==(_keyType);
}
[[nodiscard]] shared_ptr<const ScriptType> GetIndexedType(const ScriptType* indexer) const final{

View File

@@ -3,13 +3,13 @@
namespace Porygon::UserData{
extern "C" {
UserDataCollectionType* CreateCollectionType(const ScriptType* keyType, const ScriptType* valueType){
return UserDataCollectionType::CreateIndexable(keyType, valueType);
return UserDataCollectionType::CreateIndexableExtern(keyType, valueType);
}
UserDataCollectionValue* CreateCollectionValue(UserDataCollectionType* type, void* obj,
const EvalValue* (*get)(void*, const EvalValue*),
void (*set)(void*, const EvalValue*, const EvalValue*),
Iterator* (*getIterator)(void*)){
return new UserDataCollectionValue(type, new UserDataCollectionHelper(obj, get, set, getIterator));
return new UserDataCollectionValue(shared_ptr<UserDataCollectionType>(type), new UserDataCollectionHelper(obj, get, set, getIterator));
}
}
}

View File

@@ -36,18 +36,18 @@ namespace Porygon::UserData {
};
class UserDataCollectionValue : public Evaluation::EvalValue{
shared_ptr<UserDataCollectionType> _type;
shared_ptr<const UserDataCollectionType> _type;
shared_ptr<const UserDataCollectionHelper> _helper;
const size_t _hash;
UserDataCollectionValue(shared_ptr<UserDataCollectionType> type,
UserDataCollectionValue(shared_ptr<const UserDataCollectionType> type,
shared_ptr<const UserDataCollectionHelper> helper, size_t hash)
: _type(std::move(type)), _helper(std::move(helper)), _hash(hash)
{
}
public:
UserDataCollectionValue(ScriptType* type, const UserDataCollectionHelper* helper)
: _type(dynamic_cast<UserDataCollectionType*>(type)), _helper(helper), _hash(Utilities::Random::Get())
UserDataCollectionValue(shared_ptr<const ScriptType> type, const UserDataCollectionHelper* helper)
: _type(dynamic_pointer_cast<const UserDataCollectionType>(type)), _helper(helper), _hash(Utilities::Random::Get())
{
}

View File

@@ -3,6 +3,8 @@
#define PORYGONLANG_USERDATAFIELD_HPP
#include <utility>
#include "../Evaluator/EvalValues/EvalValue.hpp"
#include "../Evaluator/EvalValues/NumericEvalValue.hpp"
@@ -12,10 +14,17 @@ namespace Porygon::UserData{
const Evaluation::EvalValue* (*_get)(void* obj);
void (*_set)(void* obj, const Evaluation::EvalValue* val);
public:
UserDataField(const ScriptType* type, const Evaluation::EvalValue* (*getter)(void* obj), void (*setter)(void* obj, const Evaluation::EvalValue* val))
UserDataField(const ScriptType* type, const Evaluation::EvalValue* (*getter)(void* obj),
void (*setter)(void* obj, const Evaluation::EvalValue* val))
: _type(shared_ptr<const ScriptType>(type)), _get(getter), _set(setter){
}
UserDataField(shared_ptr<const ScriptType> type, const Evaluation::EvalValue* (*getter)(void* obj),
void (*setter)(void* obj, const Evaluation::EvalValue* val))
: _type(std::move(type)), _get(getter), _set(setter){
}
[[nodiscard]]
inline shared_ptr<const ScriptType> GetType(){
return _type;

View File

@@ -8,15 +8,15 @@
namespace Porygon::UserData{
class UserDataFunctionOption : public GenericFunctionOption{
public:
UserDataFunctionOption(std::shared_ptr<ScriptType> returnType, vector<shared_ptr<ScriptType>> parameterTypes)
UserDataFunctionOption(std::shared_ptr<const ScriptType> returnType, vector<shared_ptr<const ScriptType>> parameterTypes)
: GenericFunctionOption(std::move(returnType), std::move(parameterTypes)) {
}
static UserDataFunctionOption* FromRawPointers(ScriptType* returnType, vector<ScriptType*> parameterTypes){
auto rt = shared_ptr<ScriptType>(returnType);
auto p = vector<shared_ptr<ScriptType>>(parameterTypes.size());
static UserDataFunctionOption* FromRawPointers(const ScriptType* returnType, vector<const ScriptType*> parameterTypes){
auto rt = shared_ptr<const ScriptType>(returnType);
auto p = vector<shared_ptr<const ScriptType>>(parameterTypes.size());
for (size_t i = 0; i < parameterTypes.size(); i++){
p[i] = shared_ptr<ScriptType>(parameterTypes[i]);
p[i] = shared_ptr<const ScriptType>(parameterTypes[i]);
}
return new UserDataFunctionOption(rt, p);
}

View File

@@ -25,11 +25,11 @@
fields \
PORYGON_USERDATA_END()
#define PORYGON_INTEGER_TYPE ((Porygon::ScriptType*)new Porygon::NumericScriptType(true, false))
#define PORYGON_FLOAT_TYPE ((Porygon::ScriptType*)new Porygon::NumericScriptType(true, true))
#define PORYGON_INTEGER_TYPE (NumericScriptType::AwareInt)
#define PORYGON_FLOAT_TYPE (NumericScriptType::AwareFloat)
#define PORYGON_STRING_TYPE ((Porygon::ScriptType*)new Porygon::StringScriptType(false, 0))
#define PORYGON_INDEXABLE_TYPE(keyType, valueType) \
((Porygon::ScriptType*)Porygon::UserData::UserDataCollectionType::CreateIndexable(keyType, valueType))
(Porygon::UserData::UserDataCollectionType::CreateIndexable(keyType, valueType))
#define PORYGON_FIELD(fieldName, fieldType, getterHelper, setterHelper) \
{ \
@@ -101,7 +101,7 @@
Porygon::Utilities::HashedString::ConstHash(#fieldName), \
new Porygon::UserData::UserDataField( \
new Porygon::GenericFunctionScriptType( \
Porygon::UserData::UserDataFunctionOption::FromRawPointers(returnType, {__VA_ARGS__} )), \
new Porygon::UserData::UserDataFunctionOption(returnType, {__VA_ARGS__} )), \
\
\
[](void* obj) -> const Porygon::Evaluation::EvalValue* { \
@@ -117,7 +117,7 @@
#define PORYGON_INTEGER_FUNCTION(fieldName, ...) \
PORYGON_FUNCTION(fieldName, new Porygon::NumericScriptType(true, false), __VA_ARGS__ )
PORYGON_FUNCTION(fieldName, Porygon::NumericScriptType::AwareInt, __VA_ARGS__ )
/*!