tests working all again, with weakref parents

This commit is contained in:
David Halter
2012-08-13 01:23:29 +02:00
parent 673cb30ee8
commit 8e20c754b1
4 changed files with 62 additions and 31 deletions

View File

@@ -1,4 +1,5 @@
import copy
import weakref
import parsing
import debug
@@ -87,6 +88,42 @@ def fast_parent_copy(obj):
return copied_list
return recursion(obj)
def fast_parent_copy2(obj):
"""
Much, much faster than deepcopy, but just for the elements in `classes`.
"""
new_elements = {}
classes = (parsing.Simple)
def recursion(obj):
new_obj = copy.copy(obj)
new_elements[obj] = new_obj
if obj.parent is not None:
try:
new_obj.parent = weakref.ref(new_elements[obj.parent()])
except KeyError:
pass
#print new_obj.__dict__
for key, value in new_obj.__dict__.items():
if isinstance(value, list):
new_obj.__dict__[key] = list_rec(value)
elif isinstance(value, classes):
new_obj.__dict__[key] = recursion(value)
return new_obj
def list_rec(list_obj):
copied_list = list_obj[:] # lists, tuples, strings, unicode
for i, el in enumerate(copied_list):
if isinstance(el, classes):
copied_list[i] = recursion(el)
elif isinstance(el, list):
copied_list[i] = list_rec(el)
elif isinstance(el, parsing.Call):
copied_list[i] = fast_parent_copy(el)
return copied_list
return recursion(obj)
def generate_param_array(args_tuple, parent_stmt=None):
""" This generates an array, that can be used as a param """