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
diff --git a/scripts/hiddenapi/signature_trie.py b/scripts/hiddenapi/signature_trie.py
index e813a97..3650fa1 100644
--- a/scripts/hiddenapi/signature_trie.py
+++ b/scripts/hiddenapi/signature_trie.py
@@ -45,7 +45,9 @@
: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 @@
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 @@
# 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 []