Skip to content

Commit

Permalink
Optimize prev, first and length calculation
Browse files Browse the repository at this point in the history
ref #344
  • Loading branch information
jklmnn committed Aug 18, 2020
1 parent c5e6861 commit c72ada1
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions rflx/pyrflx/typevalue.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,12 @@ def _get_first(self, fld: str) -> Optional[Number]:
first = self.__simplified(l.first)
return first if isinstance(first, Number) else None
prv = self._prev_field(fld)
if self._skip_verification and prv:
first = self._fields[prv].first
length = self._fields[prv].typeval.size
assert isinstance(first, Number)
assert isinstance(length, Number)
return Number(first.value + length.value)
if prv and UNDEFINED not in (self._fields[prv].first, self._fields[prv].typeval.size):
first = self.__simplified(Add(self._fields[prv].first, self._fields[prv].typeval.size))
return first if isinstance(first, Number) else None
Expand Down Expand Up @@ -734,8 +740,18 @@ def check_outgoing_condition_satisfied() -> None:

if field_name in self.accessible_fields:
field = self._fields[field_name]
field_first = self._get_first(field_name)
field_length = self._get_length(field_name)
f_first = field.first
f_length = field.typeval.size
field_first = (
f_first
if self._skip_verification and isinstance(f_first, Number)
else self._get_first(field_name)
)
field_length = (
f_length
if self._skip_verification and isinstance(f_length, Number)
else self._get_length(field_name)
)
assert field_first is not None
field.first = field_first
if isinstance(field.typeval, CompositeValue) and field_length is not None:
Expand Down

0 comments on commit c72ada1

Please sign in to comment.