Skip to content

Commit c47cd13

Browse files
Attempt to improve performance.
1 parent f6ad6b6 commit c47cd13

File tree

6 files changed

+50
-24
lines changed

6 files changed

+50
-24
lines changed

src/robotide/controller/macrocontrollers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def _clear_cached_steps(self):
119119

120120
@property
121121
def max_columns(self):
122-
return max(chain((len(step.as_list()) for step in self.steps), [0]))
122+
return max(chain((len(step) for step in self.steps), [0]))
123123

124124
def has_template(self):
125125
return False
@@ -214,6 +214,7 @@ def _remove_step(self, step):
214214
self._has_steps_changed = True
215215

216216
def add_step(self, index, step=None):
217+
# print(f"\nDEBUG: _WithStepsController enter add_step step={step}")
217218
if step is None:
218219
step = _empty_step()
219220
if index == len(self.steps):

src/robotide/controller/stepcontrollers.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ class StepController(_BaseController):
2929

3030
def __init__(self, parent, step):
3131
self._init(parent, step)
32-
self._step.args = self._change_last_empty_to_empty_var(
33-
self._step.args, self._step.comment)
32+
# print(f"DEBUG: StepController After _init type(step):{type(self._step)} values: {self._step}")
33+
self._step.args = self._change_last_empty_to_empty_var(self._step.args, self._step.comment)
3434

3535
def _init(self, parent, step):
3636
self.parent = parent
@@ -42,14 +42,16 @@ def _init(self, parent, step):
4242
while index < len(self._step) and self._step[index] == '':
4343
self.indent.append('')
4444
#elif isinstance(self._step, robotapi.ForLoop):
45-
else:
45+
elif isinstance(self._step, robotapi.Step):
4646
cells = self._step.as_list()
4747
# print(f"DEBUG: StepController _init step not list: len:{len(cells)} cells:{cells[:]}")
4848
for index in range(0, len(cells)):
4949
if cells[index] == '':
5050
self.increase_indent()
51-
# else:
52-
# print(f"DEBUG: StepController _init step is not list: {type(self._step)}")
51+
else:
52+
# print(f"DEBUG: StepController _init step is not list nor Step: {type(self._step)}")
53+
self._step.args = self._step.comment= []
54+
# raise AttributeError
5355

5456
@property
5557
def display_name(self):
@@ -334,11 +336,12 @@ def _is_commented(self, col):
334336
return False
335337

336338
def _first_non_empty_cell(self):
337-
cells = self.as_list()
338-
# print(f"\nDEBUG: Stepcontrollers enter _first_non_empty_cell: cells={cells[:]}")
339-
index = 0
340-
while index < len(cells) and cells[index] == '':
341-
index += 1
339+
# cells = self.as_list()
340+
index = self._step.first_non_empty_cell()
341+
# index = 0
342+
# while index < len(cells) and cells[index] == '':
343+
# index += 1
344+
# print(f"\nDEBUG: Stepcontrollers enter _first_non_empty_cell: index1={index1} index={index}") # cells={cells[:]}")
342345
return index
343346

344347
@property
@@ -412,15 +415,15 @@ def insert_before(self, new_step):
412415
steps = self.parent.get_raw_steps()
413416
index = steps.index(self._step)
414417
if not new_step or not new_step.as_list():
415-
new_step = robotapi.Step([''])
418+
new_step = robotapi.Step([])
416419
# print(f"DEBUG: StepController, insert_before, enter: len(steps)={len(steps)} index: {index} \n"
417420
# f"new_step: {new_step.as_list()} self._step={self._step.as_list()}")
418421
if index > 0:
419-
upper_indent = self.first_non_empty_cell(steps[index-1].as_list())
420-
current_indent = self.first_non_empty_cell(new_step.as_list())
422+
upper_indent = steps[index-1].first_non_empty_cell() # self.first_non_empty_cell(steps[index-1].as_list())
423+
current_indent = new_step.first_non_empty_cell() # self.first_non_empty_cell(new_step.as_list())
421424
delta_indent = upper_indent - current_indent
422425
# print(f"DEBUG: StepController, insert_before, logic: index: {index} new_step: {new_step.as_list()}\n"
423-
# f"upper_indent({upper_indent}) current_indent({current_indent}) "
426+
# f"upper_indent({upper_indent}) current_indent({current_indent}) "
424427
# f"steps[index-1]={steps[index-1].as_list()}")
425428
if delta_indent > 0:
426429
e_list = []
@@ -562,6 +565,9 @@ def steps(self):
562565
return [IntendedStepController(self, sub_step)
563566
for sub_step in self.get_raw_steps()]
564567

568+
def __len__(self):
569+
return len(self._step)
570+
565571
"""
566572
class PartialForLoop(robotapi.ForLoop):
567573

src/robotide/lib/robot/parsing/model.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,12 @@ def decrease_indent(self):
824824
class Step(object):
825825

826826
inner_kw_pos = None
827+
name = None
828+
indent = []
829+
assign = []
830+
args = []
831+
comment = []
832+
normal_assign = None
827833

828834
def __init__(self, content, comment=None):
829835
index = self.first_non_empty_cell(content)
@@ -939,6 +945,7 @@ def as_list(self, indent=False, include_comment=True):
939945
# self.indent.insert(0, '') # Always send first indent
940946
if indent:
941947
self.indent.insert(0, '')
948+
#### return self.indent + self.assign + kw + self.args + comments # DEBUG: This code is more efficient
942949
commented_assign = False
943950
if len(kw) > 0:
944951
is_scope_set = re_set_var.match(kw[0])
@@ -968,17 +975,25 @@ def as_list(self, indent=False, include_comment=True):
968975
# f" data={data}")
969976
return data
970977

971-
def first_non_empty_cell(self, content):
978+
def first_non_empty_cell(self, content=None):
972979
# print(f"DEBUG: model enter _first_non_empty_cell")
973-
cells = content
980+
if isinstance(content, Step):
981+
size = len(content)
982+
cells = content.as_list()
983+
elif content:
984+
size = len(content)
985+
cells = content
986+
else:
987+
size = len(self)
988+
cells = self.as_list()
974989
# if cells:
975990
# print(f"DEBUG: model _first_non_empty_cell: {cells[:]}")
976991
index = 0
977-
while index < len(cells) and cells[index] == '':
992+
while index < size and cells[index] == '':
978993
index += 1
979994
if not self.inner_kw_pos:
980-
self.inner_kw_pos = index
981-
return index if index < len(cells) else index - 1
995+
self.inner_kw_pos = index if 0 <= index < size else index - 1 if index - 1 > 0 else 0
996+
return index if 0 <= index < size else index - 1 if index - 1 > 0 else 0
982997

983998
def first_empty_cell(self):
984999
index = self.inner_kw_pos
@@ -998,6 +1013,10 @@ def add_step(self, content, comment=None):
9981013
self.__init__(content, comment)
9991014
return self
10001015

1016+
def __len__(self):
1017+
kw = [self.name] if self.name is not None else []
1018+
return len(self.indent) + len(self.assign) + len(kw) + len(self.args) + len(self.comment)
1019+
10011020

10021021
class OldStyleSettingAndVariableTableHeaderMatcher(object):
10031022

test_all.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export PYTHONROOT=/usr/bin
77

88
if [ $# -ge 1 ]
99
then
10-
PY=3.9
10+
PY=3
1111
DIR="$1"
1212
else
1313
PY=3

utest/controller/base_command_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def _verify_row_does_not_exist(self, line):
104104
raise AssertionError('Row "%s" exists' % line)
105105

106106
def _verify_step_is_empty(self, index):
107-
assert self._steps[index].as_list() == ['']
107+
assert self._steps[index].as_list() == []
108108

109109
def _verify_step(self, index, exp_name, exp_args=[], exp_comment=None, kw=True):
110110
if exp_name == '':

utest/controller/test_commands.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,12 @@ def test_adding_row_last(self):
241241
def test_adding_row_first(self):
242242
self._exec(AddRow(0))
243243
assert len(self._steps) == self._orig_number_of_steps+1
244-
assert self._steps[0].as_list() == ['']
244+
assert self._steps[0].as_list() == []
245245

246246
def test_adding_row_middle(self):
247247
self._exec(AddRow(1))
248248
assert len(self._steps) == self._orig_number_of_steps+1
249-
assert self._steps[1].as_list() == ['']
249+
assert self._steps[1].as_list() == []
250250

251251
def test_adding_row_in_for_loop_body(self):
252252
row_in_for_loop = self._data_row(FOR_LOOP_STEP2)

0 commit comments

Comments
 (0)