From 211495e3ec064801eaf8161ca4bd999ec4ddfd08 Mon Sep 17 00:00:00 2001 From: Steve Holland Date: Mon, 17 Sep 2018 11:48:20 -0500 Subject: [PATCH] Add insert_multiple() method per https://github.com/PyCQA/redbaron/issues/149 to accelerate inserting multiple lines at one time. --- redbaron/base_nodes.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/redbaron/base_nodes.py b/redbaron/base_nodes.py index f681a9bc..239c70be 100644 --- a/redbaron/base_nodes.py +++ b/redbaron/base_nodes.py @@ -1418,6 +1418,17 @@ def insert(self, index, value): self.data.insert(index, [value, None]) self._synchronise() + # sdh4 11/14/17 add insert_multiple + def insert_multiple(self,index,values): + """ Insert multiple values from an iterable into the ProxyList + at the specified index, without resynchronizing after each one. """ + for value in values: + value = self._convert_input_to_node_object(value, parent=self.node_list, on_attribute=self.on_attribute) + self.data.insert(index, [value, None]) + index+=1 + pass + self._synchronise() + def append(self, value): self.insert(len(self), value)