about summary refs log tree commit diff stats
path: root/032exclusive_container.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-05-02 23:11:33 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-05-02 23:11:33 -0700
commit3377364a849d938a9999357caf26853a844b238c (patch)
treed062357677f378df7104043d498d05bee53dbeca /032exclusive_container.cc
parent481fce0e5df70332ccb3a825efcf1e5db1f3e48b (diff)
downloadmu-3377364a849d938a9999357caf26853a844b238c.tar.gz
2891 - precompute container sizes and offsets
It's a bit of a trade-off because we need to store copies of
container metadata in each reagent (to support shape-shifting
containers), and metadata is not lightweight and will get heavier. But
it'll become more unambiguously useful when we switch to a compiler.
Diffstat (limited to '032exclusive_container.cc')
-rw-r--r--032exclusive_container.cc21
1 files changed, 13 insertions, 8 deletions
diff --git a/032exclusive_container.cc b/032exclusive_container.cc
index ad82824d..e9f918f4 100644
--- a/032exclusive_container.cc
+++ b/032exclusive_container.cc
@@ -31,18 +31,23 @@ def main [
 +mem: storing 35 in location 6
 
 :(before "End size_of(type) Cases")
-if (t.kind == EXCLUSIVE_CONTAINER) {
+if (t.kind == EXCLUSIVE_CONTAINER) return get(Container_metadata, type).size;
+:(before "End compute_container_metadata Cases")
+if (info.kind == EXCLUSIVE_CONTAINER) {
+  container_metadata metadata;
   // size of an exclusive container is the size of its largest variant
   // (So like containers, it can't contain arrays.)
-  int result = 0;
-  for (int i = 0; i < SIZE(t.elements); ++i) {
-    reagent tmp;
-    tmp.type = new type_tree(*type);
-    int size = size_of(variant_type(tmp, i));
-    if (size > result) result = size;
+  int size = 0;
+  for (int i = 0; i < SIZE(info.elements); ++i) {
+    reagent element = info.elements.at(i);
+    // Compute Exclusive Container Metadata(element)
+    compute_container_metadata(element);
+    int variant_size = size_of(element);
+    if (variant_size > size) size = variant_size;
   }
   // ...+1 for its tag.
-  return result+1;
+  metadata.size = size+1;
+  Container_metadata.push_back(pair<type_tree*, container_metadata>(new type_tree(*type), metadata));
 }
 
 //:: To access variants of an exclusive container, use 'maybe-convert'.