Skip to content

Commit

Permalink
perf: use shared_ptr for tables
Browse files Browse the repository at this point in the history
This avoids leaking them while preserving the pass-by-reference
semantics.
  • Loading branch information
Oppen committed Sep 5, 2024
1 parent 3b38eb9 commit 87f1674
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions narivm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ class Value
bool has_str_rep;
string str_rep;
double num_rep;
map<string, Value> *table_rep; // TODO: this is probably a huge memory leak lol
shared_ptr<map<string, Value>> table_rep;
queue<string> *iterator_elements;

void reset_values()
Expand Down Expand Up @@ -428,7 +428,7 @@ class Value
void set_table_value()
{
reset_values();
this->table_rep = new map<string, Value>();
this->table_rep = std::make_shared<map<string, Value>>();
this->type = TABLE;
}

Expand Down Expand Up @@ -458,7 +458,7 @@ class Value

map<string, Value> *get_table()
{
return table_rep;
return table_rep.get();
}

queue<string> *get_iterator_queue()
Expand Down

0 comments on commit 87f1674

Please sign in to comment.