From 87f1674584635e58032ddb816d787e9364d00ef1 Mon Sep 17 00:00:00 2001 From: Mario Rugiero Date: Thu, 5 Sep 2024 11:36:33 -0300 Subject: [PATCH] perf: use `shared_ptr` for tables This avoids leaking them while preserving the pass-by-reference semantics. --- narivm.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/narivm.cpp b/narivm.cpp index 16f7725..846b880 100644 --- a/narivm.cpp +++ b/narivm.cpp @@ -398,7 +398,7 @@ class Value bool has_str_rep; string str_rep; double num_rep; - map *table_rep; // TODO: this is probably a huge memory leak lol + shared_ptr> table_rep; queue *iterator_elements; void reset_values() @@ -428,7 +428,7 @@ class Value void set_table_value() { reset_values(); - this->table_rep = new map(); + this->table_rep = std::make_shared>(); this->type = TABLE; } @@ -458,7 +458,7 @@ class Value map *get_table() { - return table_rep; + return table_rep.get(); } queue *get_iterator_queue()