mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 17:58:20 +00:00
small optimizations for enum props
This commit is contained in:
@@ -46,7 +46,6 @@ def purge():
|
||||
def get_ifcpatch_recipes(self, context):
|
||||
global ifcpatchrecipes_enum
|
||||
if len(ifcpatchrecipes_enum) < 1:
|
||||
ifcpatchrecipes_enum.clear()
|
||||
# Have to add a blank entry because otherwise default recipe might be not loaded
|
||||
# properly (need to ensure bim.update_ifc_patch_arguments will be called). See #5540.
|
||||
ifcpatchrecipes_enum.append(("-", "-", ""))
|
||||
@@ -58,7 +57,8 @@ def get_ifcpatch_recipes(self, context):
|
||||
continue
|
||||
docs = ifcpatch.extract_docs(f, "Patcher", "__init__", ("src", "file", "logger", "args"))
|
||||
ifcpatchrecipes_enum.append((f, f, docs.get("description", "") if docs else ""))
|
||||
return sorted(ifcpatchrecipes_enum, key=lambda x: x[0])
|
||||
ifcpatchrecipes_enum.sort(key=lambda x: x[0])
|
||||
return ifcpatchrecipes_enum
|
||||
|
||||
|
||||
def update_ifc_patch_recipe(self, context):
|
||||
|
||||
@@ -69,15 +69,16 @@ def update_global_tab(self: "BIMTabProperties", context: bpy.types.Context) -> N
|
||||
# https://blender.stackexchange.com/questions/216230/is-there-a-workaround-for-the-known-bug-in-dynamic-enumproperty
|
||||
# https://github.com/IfcOpenShell/IfcOpenShell/pull/1945
|
||||
# https://github.com/IfcOpenShell/IfcOpenShell/issues/1941
|
||||
def cache_string(s):
|
||||
# TODO: it would be nice to have some mechanism to clear that cache
|
||||
# instead of storing it forever.
|
||||
def cache_string(s: Any) -> str:
|
||||
# TODO: is it ever non-string?
|
||||
s = str(s)
|
||||
if not hasattr(cache_string, "data"): # Another way to define a function attribute
|
||||
cache_string.data = defaultdict(str)
|
||||
cache_string.data[s] = s
|
||||
return cache_string.data[s]
|
||||
return s
|
||||
|
||||
|
||||
cache_string.data = {}
|
||||
cache_string.data: dict[str, str] = {}
|
||||
|
||||
|
||||
def get_attribute_enum_values(prop: "Attribute", context: bpy.types.Context) -> list[tuple[str, str, str]]:
|
||||
@@ -96,10 +97,11 @@ def get_attribute_enum_values(prop: "Attribute", context: bpy.types.Context) ->
|
||||
)
|
||||
else:
|
||||
for e in data:
|
||||
cache_string(e)
|
||||
items.append(
|
||||
(
|
||||
cache_string(e),
|
||||
cache_string(e),
|
||||
e,
|
||||
e,
|
||||
"",
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user