Procházet zdrojové kódy

Revert "Misc changes to speed up serialization of intermediate trees"

This reverts commit 39dad4506a21338d010cf5d0be91d96a8dc2933a.
Yentl Van Tendeloo před 8 roky
rodič
revize
6144899974

+ 2 - 15
interface/HUTN/hutn_compiler/compiler.py

@@ -23,26 +23,16 @@ def md5digest(data):
     hasher.update(data)
     return hasher.hexdigest()
 
-fetch_caches = {}
-
 def fetch_cached(data, mode=None):
-    global fetch_caches
-
     try:
         md5 = md5digest(data)
-
-        if md5 in fetch_caches:
-            return fetch_caches[md5]
-
         cache_folder = os.path.abspath("%s/../caches/" % (os.path.dirname(os.path.abspath(__file__))))
         if mode is None:
             picklefile = cache_folder + "/%s.pickle" % md5
         else:
             picklefile = cache_folder + "/%s_%s.pickle" % (mode, md5)
         with open(picklefile, "rb") as f:
-            d = pickle.load(f)
-            fetch_caches[md5] = d
-            return d
+            return pickle.load(f)
     except:
         return None
 
@@ -161,10 +151,7 @@ def do_compile(inputfile, grammarfile, visitors=[], include_paths = [], mode="")
             else:
                 # The outer for finally finished, so there were no includes remaining, thus terminate the infinite while loop
                 break
-
-    pruned = result["tree"].prune()
-    import json
-    tree_data = json.dumps(pruned)
+    tree_data = pickle.dumps(result["tree"], pickle.HIGHEST_PROTOCOL)
     new_result = fetch_cached(tree_data, mode)
     if new_result is None:
         result["tree"].fix_tracability(inputfile)

+ 4 - 8
interface/HUTN/hutn_compiler/hutnparser.py

@@ -28,7 +28,6 @@ from copy import deepcopy
 
 from position import Position
 
-tail_cache = {}
 line_cache = {}
 
 class Tree(object):
@@ -37,12 +36,10 @@ class Tree(object):
         self.tail = tail
         self.startpos = startpos
         self.endpos = endpos
+        self._tail = None
         self.inputfile = inputfile
         # IMPORTANT: self.replaced: replace_child defines self.replaced
 
-    def prune(self):
-        return (self.head, [i.prune() if isinstance(i, Tree) else i for i in self.tail])
-
     def is_rule(self):
         return self.head.islower()
 
@@ -50,12 +47,11 @@ class Tree(object):
         return not self.is_rule()
 
     def get_tail(self):
-        global tail_cache
         if self.is_rule():
-            if self not in tail_cache:
-                tail_cache[self] = [t for t in self.get_raw_tail()
+            if not self._tail:
+                self._tail = [t for t in self.get_raw_tail()
                               if not t.head.startswith("implicit_autogenerated_")]
-            return tail_cache[self]
+            return self._tail
         else:
             return self.get_raw_tail()