Skip to content
Snippets Groups Projects
Commit 6688409d authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Begin symbol table performance improvement

parent 36ec09d4
No related branches found
No related tags found
1 merge request!37Feature/language
......@@ -783,23 +783,10 @@ class SymbolTable
};
private:
std::unordered_map<std::string, Attributes> m_symbol_list;
std::vector<std::pair<std::string, Attributes>> m_symbol_list;
std::shared_ptr<SymbolTable> m_parent_table;
public:
void
removeUnmatchedSymbols(const SymbolTable& given_table)
{
Assert(m_parent_table == given_table.m_parent_table);
for (decltype(m_symbol_list)::iterator i_symbol = m_symbol_list.begin(); i_symbol != m_symbol_list.end();) {
if (given_table.m_symbol_list.find(i_symbol->first) == given_table.m_symbol_list.end()) {
i_symbol = m_symbol_list.erase(i_symbol);
} else {
++i_symbol;
}
}
}
friend std::ostream&
operator<<(std::ostream& os, const SymbolTable& symbol_table)
{
......@@ -814,7 +801,15 @@ class SymbolTable
auto
find(const std::string& symbol)
{
auto i_symbol = m_symbol_list.find(symbol);
auto i_symbol = m_symbol_list.end();
for (auto i_stored_symbol = m_symbol_list.begin(); i_stored_symbol != m_symbol_list.end(); ++i_stored_symbol) {
if (i_stored_symbol->first == symbol) {
i_symbol = i_stored_symbol;
break;
}
}
if (i_symbol != m_symbol_list.end()) {
return std::make_pair(i_symbol, true);
} else {
......@@ -829,7 +824,12 @@ class SymbolTable
auto
add(const std::string& symbol)
{
return m_symbol_list.insert(std::make_pair(symbol, Attributes{}));
for (auto i_stored_symbol = m_symbol_list.begin(); i_stored_symbol != m_symbol_list.end(); ++i_stored_symbol) {
if (i_stored_symbol->first == symbol) {
return std::make_pair(i_stored_symbol, false);
}
}
return std::make_pair(m_symbol_list.emplace(m_symbol_list.end(), std::make_pair(symbol, Attributes())), true);
}
SymbolTable(const std::shared_ptr<SymbolTable>& parent_table = nullptr) : m_parent_table(parent_table)
......@@ -1688,7 +1688,6 @@ execute_node(Node& n, std::shared_ptr<SymbolTable>& symbol_table, ExecPolicyT& e
}
}
bloc_symbol_table->removeUnmatchedSymbols(context_symbol_table);
execute_node(*n.children[2], bloc_symbol_table, exec_policy);
}
break;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment