forked from VimPlug/jedi
deepcopy removed at one place, tests being 12s faster (from 20s to 8s)
This commit is contained in:
@@ -245,7 +245,8 @@ class InstanceElement(object):
|
|||||||
# Copy and modify the array.
|
# Copy and modify the array.
|
||||||
origin = self.var.get_assignment_calls()
|
origin = self.var.get_assignment_calls()
|
||||||
origin.parent_stmt, temp = None, origin.parent_stmt
|
origin.parent_stmt, temp = None, origin.parent_stmt
|
||||||
new = copy.deepcopy(origin)
|
# Delete parent, because it isn't used anymore.
|
||||||
|
new = helpers.fast_parent_copy(origin)
|
||||||
origin.parent_stmt = temp
|
origin.parent_stmt = temp
|
||||||
new.parent_stmt = InstanceElement(self.instance, temp)
|
new.parent_stmt = InstanceElement(self.instance, temp)
|
||||||
return new
|
return new
|
||||||
|
|||||||
32
helpers.py
32
helpers.py
@@ -1,5 +1,6 @@
|
|||||||
import parsing
|
import parsing
|
||||||
import debug
|
import debug
|
||||||
|
import copy
|
||||||
|
|
||||||
class RecursionDecorator(object):
|
class RecursionDecorator(object):
|
||||||
""" A decorator to detect recursions in statements """
|
""" A decorator to detect recursions in statements """
|
||||||
@@ -45,3 +46,34 @@ class RecursionNode(object):
|
|||||||
if not other:
|
if not other:
|
||||||
return None
|
return None
|
||||||
return self.script == other.script and self.position == other.position
|
return self.script == other.script and self.position == other.position
|
||||||
|
|
||||||
|
|
||||||
|
def fast_parent_copy(obj):
|
||||||
|
"""
|
||||||
|
Much, much faster than deepcopy, but just for the elements in `classes`.
|
||||||
|
"""
|
||||||
|
new_elements = {}
|
||||||
|
classes = (parsing.Call, parsing.Scope)
|
||||||
|
def recursion(obj):
|
||||||
|
new_obj = copy.copy(obj)
|
||||||
|
new_elements[obj] = new_obj
|
||||||
|
try:
|
||||||
|
new_obj.parent = 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)
|
||||||
|
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)
|
||||||
|
return copied_list
|
||||||
|
return recursion(obj)
|
||||||
|
|||||||
Reference in New Issue
Block a user