Skip to content

Commit

Permalink
add feature enhanced inline reference
Browse files Browse the repository at this point in the history
- increased performance for inline references pointing to SHORT-NAME
- referenced element won't be looked up
- SHORT-NAME will be directly extracted from the reference itself
  • Loading branch information
Jürgen Altszeimer committed Apr 30, 2020
1 parent 0e5a872 commit 4496ded
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 7 additions & 0 deletions arxml_data_extractor/handler/path_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ def element_by_inline_ref(self, path: DataQuery.XPath, node: Element) -> Union[E
)
return None

# if inline reference and value path is SHORT-NAME, it skips getting referenced element
# to increase parsing performance. Instead the element containing the reference is returned.
# This is only possible because the SHORT-NAME can be extracted directly from reference.text.
# The special treatment is implemented in ValueHandler.
if path_to_value == 'SHORT-NAME':
return reference

referred_element = self.element_by_ref(reference.text)
return self.element_by_xpath(path_to_value, referred_element)

Expand Down
9 changes: 8 additions & 1 deletion arxml_data_extractor/handler/value_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@


def handle(query: DataQuery, node: Element) -> Any:
value = __get_value(query.value, node)
# Special treatment for inline references pointing to the references SHORT-NAME
if isinstance(query.path, DataQuery.XPath) \
and query.path.is_reference \
and query.path.xpath.endswith(')SHORT-NAME'):
value = node.text.split('/')[-1]
else:
value = __get_value(query.value, node)

if value is None:
return value
return __convert_value(value, query.format)
Expand Down

0 comments on commit 4496ded

Please sign in to comment.