From c0fdff872ca2c48939bacfefce020878ef92b44c Mon Sep 17 00:00:00 2001 From: olpc user Date: Sat, 23 Nov 2019 02:53:41 -0800 Subject: make memory store a set <- waste of time --- starts/meaning-vm/memorystore.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'starts/meaning-vm') diff --git a/starts/meaning-vm/memorystore.cpp b/starts/meaning-vm/memorystore.cpp index 4178a4b..c759051 100644 --- a/starts/meaning-vm/memorystore.cpp +++ b/starts/meaning-vm/memorystore.cpp @@ -1,20 +1,23 @@ #include "memorystore.hpp" -#include -#include +#include using namespace std; -std::vector concepts; +auto & concepts() +{ + static std::unordered_set concepts; + return concepts; +} ref alloc(concept * moved) { ref r = moved ? moved : new concept(); - concepts.push_back(r.ptr); + concepts().insert(r.ptr); return r; } bool referenced(ref r) { - for (ref r2 : concepts) { + for (ref r2 : concepts()) { if (r2 == r) { continue; } @@ -35,12 +38,12 @@ void dealloc(ref r) { throw std::logic_error("concept is referenced"); } for ( - auto it = concepts.begin(); - it != concepts.end(); + auto it = concepts().begin(); + it != concepts().end(); ++ it) { if (ref(*it) == r) { - concepts.erase(it); + concepts().erase(it); delete r.ptr; return; } -- cgit v1.2.3