From 1bdcf6c5139ac3d7079c274ea5af1f003d25afd4 Mon Sep 17 00:00:00 2001 From: Eivind Jahren Date: Thu, 14 Dec 2023 13:43:58 +0100 Subject: [PATCH] Improve unformatted reading performance --- src/resfo/_unformatted/common.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/resfo/_unformatted/common.py b/src/resfo/_unformatted/common.py index 28031da..953d16e 100644 --- a/src/resfo/_unformatted/common.py +++ b/src/resfo/_unformatted/common.py @@ -1,3 +1,6 @@ +from functools import lru_cache + + def group_len(type_keyword): """ The length of element groups in unformatted arrays. @@ -21,6 +24,7 @@ def group_len(type_keyword): } +@lru_cache def item_size(type_keyword): """ :returns: The number of bytes for each element in an @@ -28,9 +32,10 @@ def item_size(type_keyword): """ if type_keyword[0:2] == b"C0": return int(type_keyword[2:4].decode("ascii")) - return static_item_sizes.get(type_keyword, None) + return static_item_sizes.get(type_keyword) +@lru_cache def bytes_in_array(array_length, item_type): """ :param array_length: Number of items in the array