Skip to content

Commit d3bae4a

Browse files
dlatypovshuahkh
authored andcommitted
kunit: tool: simplify kconfig is_subset_of() logic
Don't use an O(nm) algorithm* and make it more readable by using a dict. *Most obviously, it does a nested for-loop over the entire other config. A bit more subtle, it calls .entries(), which constructs a set from the list for _every_ outer iteration. Signed-off-by: Daniel Latypov <[email protected]> Reviewed-by: David Gow <[email protected]> Tested-by: Brendan Higgins <[email protected]> Acked-by: Brendan Higgins <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent cd4a9bc commit d3bae4a

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

tools/testing/kunit/kunit_config.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,14 @@ def add_entry(self, entry: KconfigEntry) -> None:
4141
self._entries.append(entry)
4242

4343
def is_subset_of(self, other: 'Kconfig') -> bool:
44+
other_dict = {e.name: e.value for e in other.entries()}
4445
for a in self.entries():
45-
found = False
46-
for b in other.entries():
47-
if a.name != b.name:
46+
b = other_dict.get(a.name)
47+
if b is None:
48+
if a.value == 'n':
4849
continue
49-
if a.value != b.value:
50-
return False
51-
found = True
52-
if a.value != 'n' and found == False:
50+
return False
51+
elif a.value != b:
5352
return False
5453
return True
5554

0 commit comments

Comments
 (0)