Skip to contentSkip to conversation

kunit: tool: simplify kconfig is_subset_of() logic

PATCH In review Daniel Latypov 3 participants 3 messages Dec 8, 2020 – Feb 6, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 tools/testing/kunit/kunit_config.py | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
tools/testing/kunit/kunit_config.py +6 -7
index 02ffc3a3e5dc..f1101075d458 100644
@@ -40,15 +40,14 @@ class Kconfig(object):
 		self._entries.append(entry)
 
 	def is_subset_of(self, other: 'Kconfig') -> bool:
+		other_dict = {e.name: e.value for e in other.entries()}
 		for a in self.entries():
-			found = False
-			for b in other.entries():
-				if a.name != b.name:
+			b = other_dict.get(a.name)
+			if b is None:
+				if a.value == 'n':
 					continue
-				if a.value != b.value:
-					return False
-				found = True
-			if a.value != 'n' and found == False:
+				return False
+			elif a.value != b:
 				return False
 		return True
 

base-commit: c6f7e1510b872c281ff603a3108c084b6548d35c

Signature · 1 line
2.29.2.576.ga3fc446d84-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Daniel Latypov

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.

---

Thanks! This works great here: I didn't time it to see how much faster it is, but it's clearly an improvement.

Cheers,
-- David

Tested-by Acked-by on v1 1/1
#2 lore raw
In reply to Daniel Latypov
Quoted 8 lines · Daniel Latypov

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.