From 67b539aba14e4c0e970dfe6f189cca0acfb4ca03 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Fri, 13 Jun 2025 16:43:53 +0500 Subject: [PATCH] remove_representation - optimization In some cases remove_representation got 2x times faster (when there were a lot representation items that are not IfcTessellatedFaceSets). getattr with attribute that might not be present on the element could be much slower then checking it's class explicitly. --- .../ifcopenshell/api/geometry/remove_representation.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/api/geometry/remove_representation.py b/src/ifcopenshell-python/ifcopenshell/api/geometry/remove_representation.py index 080ba29d64..3e31c8de6f 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/geometry/remove_representation.py +++ b/src/ifcopenshell-python/ifcopenshell/api/geometry/remove_representation.py @@ -51,8 +51,9 @@ def remove_representation( for s in subelement.LayerAssignment if not is_ifc2x3 else subelement.LayerAssignments: presentation_layer_assignments_items.add(s) # IfcTessellatedFaceSet inverses - [textures.add(t) for t in getattr(subelement, "HasTextures", []) or []] - [colours.add(t) for t in getattr(subelement, "HasColours", []) or []] + if subelement.is_a() == "IfcTessellatedFaceSet": + textures.update(subelement.HasTextures) + colours.update(subelement.HasColours) elif subelement.is_a("IfcRepresentation"): for layer in subelement.LayerAssignments: presentation_layer_assignments_reps.add(layer)