Skip to content

Commit c9adcae

Browse files
authored
Merge pull request #296 from sneakers-the-rat/perf-schemaview
Perf: Remove unnecessary `deepcopy` calls in `Schemaview.induced_slot`
2 parents cbe0300 + fe8e821 commit c9adcae

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

linkml_runtime/utils/schemaview.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,15 +1224,16 @@ def induced_slot(self, slot_name: SLOT_NAME, class_name: CLASS_NAME = None, impo
12241224
:param imports: include imports closure
12251225
:return: dynamic slot constructed by inference
12261226
"""
1227-
slot = self.get_slot(slot_name, imports, attributes=False)
12281227
if class_name:
12291228
cls = self.get_class(class_name, imports, strict=True)
12301229
else:
12311230
cls = None
1231+
12321232
# attributes take priority over schema-level slot definitions, IF
12331233
# the attributes is declared for the class or an ancestor
12341234
slot_comes_from_attribute = False
12351235
if cls:
1236+
slot = self.get_slot(slot_name, imports, attributes=False)
12361237
# traverse ancestors (reflexive), starting with
12371238
# the main class
12381239
for an in self.class_ancestors(class_name):
@@ -1243,19 +1244,21 @@ def induced_slot(self, slot_name: SLOT_NAME, class_name: CLASS_NAME = None, impo
12431244
break
12441245
else:
12451246
slot = self.get_slot(slot_name, imports, attributes=True)
1247+
12461248
if slot is None:
12471249
raise ValueError(f"No such slot {slot_name} as an attribute of {class_name} ancestors "
12481250
"or as a slot definition in the schema")
1251+
12491252
# copy the slot, as it will be modified
1250-
induced_slot = deepcopy(slot)
1253+
induced_slot = copy(slot)
12511254
if not slot_comes_from_attribute:
12521255
slot_anc_names = self.slot_ancestors(slot_name, reflexive=True)
12531256
# inheritable slot: first propagate from ancestors
12541257
for anc_sn in reversed(slot_anc_names):
12551258
anc_slot = self.get_slot(anc_sn, attributes=False)
12561259
for metaslot_name in SlotDefinition._inherited_slots:
12571260
if getattr(anc_slot, metaslot_name, None):
1258-
setattr(induced_slot, metaslot_name, deepcopy(getattr(anc_slot, metaslot_name)))
1261+
setattr(induced_slot, metaslot_name, copy(getattr(anc_slot, metaslot_name)))
12591262
COMBINE = {
12601263
'maximum_value': lambda x, y: min(x, y),
12611264
'minimum_value': lambda x, y: max(x, y),
@@ -1302,7 +1305,7 @@ def induced_slot(self, slot_name: SLOT_NAME, class_name: CLASS_NAME = None, impo
13021305
if induced_slot.name in c.slots or induced_slot.name in c.attributes:
13031306
if c.name not in induced_slot.domain_of:
13041307
induced_slot.domain_of.append(c.name)
1305-
return deepcopy(induced_slot)
1308+
return induced_slot
13061309

13071310
@lru_cache()
13081311
def _metaslots_for_slot(self):

0 commit comments

Comments
 (0)