mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
Possible optimisation by caching in IfcTester property checks
This commit is contained in:
@@ -21,6 +21,7 @@ import builtins
|
||||
import ifcopenshell.util.unit
|
||||
import ifcopenshell.util.element
|
||||
import ifcopenshell.util.classification
|
||||
from functools import lru_cache
|
||||
from xmlschema.validators import identities
|
||||
|
||||
|
||||
@@ -41,6 +42,16 @@ def cast_to_value(from_value, to_value):
|
||||
pass
|
||||
|
||||
|
||||
@lru_cache
|
||||
def get_pset(element, pset):
|
||||
return ifcopenshell.util.element.get_pset(element, pset)
|
||||
|
||||
|
||||
@lru_cache
|
||||
def get_psets(element, pset):
|
||||
return ifcopenshell.util.element.get_psets(element)
|
||||
|
||||
|
||||
class Facet:
|
||||
def __init__(self, *parameters):
|
||||
self.status = None
|
||||
@@ -591,10 +602,10 @@ class Property(Facet):
|
||||
return PropertyResult(True)
|
||||
|
||||
if isinstance(self.propertySet, str):
|
||||
pset = ifcopenshell.util.element.get_pset(inst, self.propertySet)
|
||||
pset = get_pset(inst, self.propertySet)
|
||||
psets = {self.propertySet: pset} if pset else {}
|
||||
else:
|
||||
all_psets = ifcopenshell.util.element.get_psets(inst)
|
||||
all_psets = get_psets(inst)
|
||||
psets = {k: v for k, v in all_psets.items() if k == self.propertySet}
|
||||
|
||||
is_pass = bool(psets)
|
||||
|
||||
@@ -21,7 +21,7 @@ import datetime
|
||||
from xmlschema import XMLSchema
|
||||
from xmlschema import etree_tostring
|
||||
from xml.etree import ElementTree as ET
|
||||
from .facet import Entity, Attribute, Classification, Property, PartOf, Material, Restriction
|
||||
from .facet import Entity, Attribute, Classification, Property, PartOf, Material, Restriction, get_pset, get_psets
|
||||
|
||||
|
||||
cwd = os.path.dirname(os.path.realpath(__file__))
|
||||
@@ -113,6 +113,8 @@ class Ids:
|
||||
return get_schema().is_valid(filepath)
|
||||
|
||||
def validate(self, ifc_file, filter_version=False):
|
||||
get_pset.cache_clear()
|
||||
get_psets.cache_clear()
|
||||
for specification in self.specifications:
|
||||
specification.reset_status()
|
||||
specification.validate(ifc_file, filter_version=filter_version)
|
||||
|
||||
Reference in New Issue
Block a user