##// END OF EJS Templates
Replace O(N^2) algorithm with a faster one.
Jonathan Frederic -
Show More
@@ -36,13 +36,17 b' class ContainerWidget(DOMWidget):'
36 """Validate children list.
36 """Validate children list.
37
37
38 Makes sure only one instance of any given model can exist in the
38 Makes sure only one instance of any given model can exist in the
39 children list."""
39 children list.
40 An excellent post on uniqifiers is available at
41 http://www.peterbe.com/plog/uniqifiers-benchmark
42 which provides the inspiration for using this implementation. Below
43 I've implemented the `f5` algorithm using Python comprehensions."""
40 if new is not None and isinstance(new, list):
44 if new is not None and isinstance(new, list):
41 children = []
45 seen = {}
42 for child in new:
46 def add_item(i):
43 if child not in children:
47 seen[i.model_id] = True
44 children.append(child)
48 return i
45 self._children = children
49 return [add_item(i) for i in new if not i.model_id in seen]
46
50
47
51
48 class PopupWidget(ContainerWidget):
52 class PopupWidget(ContainerWidget):
General Comments 0
You need to be logged in to leave comments. Login now