summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorolpc user <olpc@xo-5d-f7-86.localdomain>2019-11-23 02:53:41 -0800
committerolpc user <olpc@xo-5d-f7-86.localdomain>2019-11-23 02:53:41 -0800
commitc0fdff872ca2c48939bacfefce020878ef92b44c (patch)
tree220d8f175a68b68d1656ce2ce377bb185f8d57af
parentdd35e6f5cf4bda4ae17d7611fbc138fdbdf60c8b (diff)
downloadstandingwithresilience-c0fdff872ca2c48939bacfefce020878ef92b44c.tar.gz
standingwithresilience-c0fdff872ca2c48939bacfefce020878ef92b44c.zip
make memory store a set <- waste of time
-rw-r--r--starts/meaning-vm/memorystore.cpp19
1 files changed, 11 insertions, 8 deletions
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 <list>
-#include <vector>
+#include <unordered_set>
using namespace std;
-std::vector<concept*> concepts;
+auto & concepts()
+{
+ static std::unordered_set<concept*> 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;
}