1. Carl Friedrich Bolz
  2. Pyrolog

Commits

Carl Friedrich Bolz  committed 5feef4f

write get_full_storage equivalently to set_full_storage

  • Participants
  • Parent commits 42272bc
  • Branches compress-terms2

Comments (0)

Files changed (1)

File prolog/interpreter/shape.py

View file
             mode = intmask((1000003 * mode) ^ y)
         return mode
 
-unroll_n = unroll.unrolling_iterable(range(SHAPED_CALLABLE_SIZE))
-unroll_r = unroll.unrolling_iterable(range(SHAPED_CALLABLE_SIZE)[::-1])
+UNROLL_N = unroll.unrolling_iterable(range(SHAPED_CALLABLE_SIZE))
+UNROLL_R = unroll.unrolling_iterable(range(SHAPED_CALLABLE_SIZE)[::-1])
 
 class ShapedCallableMixin:
     TYPE_STANDARD_ORDER = term.Term.TYPE_STANDARD_ORDER
         self.shape = shape
 
     def get_storage(self, i):
-        for n in unroll_n:
+        for n in UNROLL_N:
             if i == n:
                 return getattr(self, "a%s" % n)
         return self.rest_storage[i - SHAPED_CALLABLE_SIZE]
 
     def set_storage(self, i, val):
-        for n in unroll_n:
+        for n in UNROLL_N:
             if i == n:
                 setattr(self, "a%s" % n, val)
                 break
 
 
     def get_full_storage(self):
-        result = [None] * self.size_storage()
-        for i in range(len(result)):
-            result[i] = self.get_storage(i)
+        # this is very much over the top, but it was fun to do
+        size = self.size_storage()
+        result = [None] * min(size, SHAPED_CALLABLE_SIZE)
+        if size == 0:
+            return result
+        for n in UNROLL_N:
+            if size == n + 1:
+                break
+        else:
+            result = result + self.rest_storage
+            n = SHAPED_CALLABLE_SIZE - 1
+        for i in UNROLL_R:
+            if n == i:
+                result[i] = getattr(self, "a%s" % i)
+                n = i - 1
         return result
 
     def set_full_storage(self, storage):
         if size == 0:
             return
         # the trick: "promote" size
-        for n in unroll_n:
+        for n in UNROLL_N:
             if size == n + 1:
                 break
         else:
             self.rest_storage = storage[SHAPED_CALLABLE_SIZE:]
             n = SHAPED_CALLABLE_SIZE - 1
-        for i in unroll_r:
+        for i in UNROLL_R:
             if n == i:
                 setattr(self, "a%s" % i, storage[i])
                 n = i - 1