Skip to content

Commit

Permalink
Use QString in QMap.
Browse files Browse the repository at this point in the history
Noticed perfomance drops when using QStringView as a key in QMap.
  • Loading branch information
zadockmaloba committed Nov 30, 2023
1 parent ce1981d commit 11b6c38
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 29 deletions.
6 changes: 3 additions & 3 deletions src/serverlangcore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace ServerLang {

const std::shared_ptr<QVariant> Core::exec(QStringView symbol, const QVariantMap &args) throw()
{
if(auto _mp = CoreFunctions::functionMap(); _mp.find(symbol) != _mp.end()) {
auto func = _mp[symbol];
if (auto _mp = CoreFunctions::functionMap(); _mp.find(symbol.toString()) != _mp.end()) {
auto func = _mp[symbol.toString()];
CoreFunctions::registerParameters(args);
return func();
}
Expand All @@ -23,7 +23,7 @@ const void Core::define(const STNode::nodeptr &func) throw()
auto const ret = QVariant::fromValue(func);
return std::make_shared<QVariant>(ret);
};
CoreFunctions::functionMap().insert({func->name(), opr});
CoreFunctions::functionMap().insert({func->name().toString(), opr});
}

} // namespace ServerLang
Expand Down
24 changes: 12 additions & 12 deletions src/serverlangfunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CoreFunctions
public:
CoreFunctions() = default;

static std::map<QStringView, const ast_operator> &functionMap() { return m_functionMap; }
static std::map<const QString, const ast_operator> &functionMap() { return m_functionMap; }

static void registerParameters(const QVariantMap &params)
{
Expand All @@ -43,7 +43,7 @@ class CoreFunctions

private://registers
static QVariantMap args_reg, params_reg;
static std::map<QStringView, const ast_operator> m_functionMap;
static std::map<const QString, const ast_operator> m_functionMap;
};

inline QVariantMap CoreFunctions::args_reg = {};
Expand Down Expand Up @@ -243,16 +243,16 @@ inline const ast_operator CoreFunctions::jsnstringify = []()mutable->value_ptr
return std::make_shared<QVariant>(string);
};

inline std::map<QStringView, const ast_operator> CoreFunctions::m_functionMap
= {{QString("Core::Exec"), exec_cmd},
{QString("Core::Println"), println},
{QString("Core::FileRead"), readfile},
{QString("Core::FileWrite"), writefile},
{QString("Core::Db::Open"), dbopen},
{QString("Core::Db::Exec"), dbexec},
{QString("Core::Db::Close"), dbclose},
{QString("Core::Json::Make"), mkjson},
{QString("Core::Json::Stringify"), jsnstringify}};
inline std::map<const QString, const ast_operator> CoreFunctions::m_functionMap
= {{"Core::Exec", exec_cmd},
{"Core::Println", println},
{"Core::FileRead", readfile},
{"Core::FileWrite", writefile},
{"Core::Db::Open", dbopen},
{"Core::Db::Exec", dbexec},
{"Core::Db::Close", dbclose},
{"Core::Json::Make", mkjson},
{"Core::Json::Stringify", jsnstringify}};
} // namespace ServerLang
}

Expand Down
5 changes: 2 additions & 3 deletions src/serverlangnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ namespace ServerLang {
const STNode::nodeptr STNode::check_for_declaration(QStringView name)
{
qDebug() << "Checking for: " << name << " in: " << this->name();
if(declarationMap().has(name)){
if (declarationMap().has(name)) {
return declarationMap().at(name);
}
else if(parentScope().get() != nullptr)
} else if (parentScope().get() != nullptr)
return parentScope()->check_for_declaration(name);

//throw "WARNING: Unable to find referenced variable";
Expand Down
4 changes: 2 additions & 2 deletions src/serverlangruntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,10 @@ void RunTime::UPDATE_SCOPE_DECLARATIONS_VALUE(const QString &vname, QVariantMap
scope.find("declarations").value() = decl;
}

const QMap<QString, std::function<const QVariantMap ()> > &RunTime::hookMap() const
const QMap<const QString, std::function<const QVariantMap()> > &RunTime::hookMap() const
{return m_hookMap;}

void RunTime::setHookMap(const QMap<QString, std::function<const QVariantMap ()> > &newHookMap)
void RunTime::setHookMap(const QMap<const QString, std::function<const QVariantMap()> > &newHookMap)
{m_hookMap = newHookMap;}

const STNode::nodeptr &RunTime::BufferAST() const
Expand Down
18 changes: 9 additions & 9 deletions src/serverlangruntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class RunTime
const STNode::nodeptr &BufferAST() const;
void setBufferAST(const STNode::nodeptr &newBufferAST);

const QMap<QString, std::function<const QVariantMap ()> > &hookMap() const;
void setHookMap(const QMap<QString, std::function<const QVariantMap ()> > &newHookMap);
const QMap<const QString, std::function<const QVariantMap()>> &hookMap() const;
void setHookMap(const QMap<const QString, std::function<const QVariantMap()>> &newHookMap);

void interprate(const STNode::nodeptr &ast);

Expand Down Expand Up @@ -108,13 +108,13 @@ class RunTime
}

private:
QMap<QString, std::function<void()>> m_functionMap;
QMap<QString, std::function<const QVariantMap ()>> m_hookMap;
//std::map<QString, std::shared_ptr<DatabaseHandler>> m_databaseMap;
DatabasePool m_databaseMap;
STNode::nodeptr m_BufferAST, m_tmpParentScope;
QVariantMap::Iterator m_BufferCursor;
std::shared_ptr<DatabaseHandler> m_dbHandler;
QMap<const QString, std::function<void()>> m_functionMap;
QMap<const QString, std::function<const QVariantMap()>> m_hookMap;
//std::map<QString, std::shared_ptr<DatabaseHandler>> m_databaseMap;
DatabasePool m_databaseMap;
STNode::nodeptr m_BufferAST, m_tmpParentScope;
QVariantMap::Iterator m_BufferCursor;
std::shared_ptr<DatabaseHandler> m_dbHandler;

private:
static const QRegularExpression arrmatch;
Expand Down

0 comments on commit 11b6c38

Please sign in to comment.