corenova / yang-js

YANG parser and composer
Apache License 2.0
56 stars 18 forks source link

optimize XPath.process used inside Property.in and Property.find for matching direct key based list item #78

Closed sekur closed 5 years ago

sekur commented 5 years ago

Currently, the XPath.process performs a generic operation which is to collect all possible entities into an array first before performing predicate filtering. In the case where the predicate filter applies to a direct key match for a list item, we can short-circuit this process by using the List internal Map data to directly retrieve the list item instead of searching through the entire list for finding the match.

Created as a separate enhancement for issue #73 reported by @quantang

sekur commented 5 years ago

I'm considering making List elements return a Map instead of an Array. This may potentially break prior get operations involving List but seems that it may make more sense to directly expose the internal state already using Map when the property getter is used instead of transforming into an Array. @quantang - any thoughts?

quantang commented 5 years ago

Shall we have some way, such as an additional option or a function, to return the internal state for XPath? Returning an Array for a List element is intuitive for the external users. While I guess the intention of the "get" is different from the "find", if we can return the Map for "find" and return the Array for "get", that would be perfect.

sekur commented 5 years ago

Latest 0.22 branch fixes this issue.