@@ -1487,29 +1487,32 @@ def slot_range_as_union(self, slot: SlotDefinition) -> List[ElementName]:
14871487 if x .range :
14881488 range_union_of .append (x .range )
14891489 return range_union_of
1490-
1491- def get_classes_by_slot (self , slot : SlotDefinition , include_induced : bool = False ) -> List [ClassDefinitionName ]:
1490+
1491+ def get_classes_by_slot (
1492+ self , slot : SlotDefinition , include_induced : bool = False
1493+ ) -> List [ClassDefinitionName ]:
14921494 """Get all classes that use a given slot, either as a direct or induced slot.
14931495
14941496 :param slot: slot in consideration
14951497 :param include_induced: supplement all direct slots with induced slots, defaults to False
14961498 :return: list of slots, either direct, or both direct and induced
14971499 """
1498- slots_list = [] # list of all direct or induced slots
1500+ classes_set = set () # use set to avoid duplicates
1501+ all_classes = self .all_classes ()
14991502
1500- for c_name , c in self .all_classes ().items ():
1501- # check if slot is direct specification on class
1503+ for c_name , c in all_classes .items ():
15021504 if slot .name in c .slots :
1503- slots_list . append (c_name )
1505+ classes_set . add (c_name )
15041506
1505- # include induced classes also if requested
15061507 if include_induced :
1507- for c_name , c in self .all_classes ().items ():
1508- for ind_slot in self .class_induced_slots (c_name ):
1509- if ind_slot .name == slot .name :
1510- slots_list .append (c_name )
1511-
1512- return list (dict .fromkeys (slots_list ))
1508+ for c_name in all_classes :
1509+ induced_slot_names = [
1510+ ind_slot .name for ind_slot in self .class_induced_slots (c_name )
1511+ ]
1512+ if slot .name in induced_slot_names :
1513+ classes_set .add (c_name )
1514+
1515+ return list (classes_set )
15131516
15141517 @lru_cache ()
15151518 def get_slots_by_enum (self , enum_name : ENUM_NAME = None ) -> List [SlotDefinition ]:
0 commit comments