diff options
author | 2022-04-01 15:04:23 +0100 | |
---|---|---|
committer | 2022-04-01 15:04:23 +0100 | |
commit | dbbb8374a2c2dea5093041f77579c3994473515a (patch) | |
tree | 227e4bae4cbb9e8227ab5fe024e87b3bf1888007 /scripts/hiddenapi/signature_trie.py | |
parent | 3aae38d451e44d7f12224e938456dfb2fd665ac5 (diff) |
signature_trie: Avoid unnecessary wrapping and unwrapping of values
Previously, Leaf.values() and Leaf.append_values() would wrap the
Leaf's value inside a list before appending it to the list of values.
So, the values list was actually a list of lists of values. The
get_matching_rows method would then use chain.from_iterable() to
flatten that list of list of values into a list of values.
This change removes the initial wrapping in a list and so removes the
need to flatten them into a single list. It also adds a test for the
values() method. Prior to this change the expected value would have
been [[1], ["A"], [{}]].
Bug: 202154151
Test: atest --host analyze_bcpf_test signature_trie_test verify_overlaps_test
Change-Id: Ida78500c9ab4466de127b2c36501b3606d0f3fe5
Diffstat (limited to 'scripts/hiddenapi/signature_trie.py')
-rw-r--r-- | scripts/hiddenapi/signature_trie.py | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/scripts/hiddenapi/signature_trie.py b/scripts/hiddenapi/signature_trie.py index e813a9781..3650fa159 100644 --- a/scripts/hiddenapi/signature_trie.py +++ b/scripts/hiddenapi/signature_trie.py @@ -45,7 +45,9 @@ class Node: :return: A list of iterables of all the values associated with this node and its children. """ - raise NotImplementedError("Please Implement this method") + values = [] + self.append_values(values, selector) + return values def append_values(self, values, selector): """Append the values associated with this node and its children. @@ -313,12 +315,8 @@ class InteriorNode(Node): node = node.nodes[element] else: return [] - return chain.from_iterable(node.values(selector)) - def values(self, selector): - values = [] - self.append_values(values, selector) - return values + return node.values(selector) def append_values(self, values, selector): for key, node in self.nodes.items(): @@ -336,11 +334,8 @@ class Leaf(Node): # The value associated with this leaf. value: typing.Any - def values(self, selector): - return [[self.value]] - def append_values(self, values, selector): - values.append([self.value]) + values.append(self.value) def child_nodes(self): return [] |