diff --git a/tests/test_util_core.py b/tests/test_util_core.py index 95b97a90..1ff3fb6d 100644 --- a/tests/test_util_core.py +++ b/tests/test_util_core.py @@ -40,7 +40,7 @@ def test_str_flag_to_int(): assert flag == flags[0] for v in versions: - assert v in _flag_cache + assert f"BufferUsage.{v}" in _flag_cache if __name__ == "__main__": diff --git a/wgpu/_coreutils.py b/wgpu/_coreutils.py index 49485097..1365412e 100644 --- a/wgpu/_coreutils.py +++ b/wgpu/_coreutils.py @@ -44,8 +44,13 @@ def error_message_hash(message): def str_flag_to_int(flag, s): - """Allow using strings for flags, i.e. 'READ' instead of wgpu.MapMode.READ.""" - value = _flag_cache.get(s, None) + """Allow using strings for flags, i.e. 'READ' instead of wgpu.MapMode.READ. + No worries about repeated overhead, because the resuls are cached. + """ + cache_key = ( + f"{flag._name}.{s}" # using private attribute, lets call this a friend func + ) + value = _flag_cache.get(cache_key, None) if value is None: parts = [p.strip() for p in s.split("|")] @@ -61,7 +66,7 @@ def str_flag_to_int(flag, s): value += v except KeyError: raise ValueError(f"Invalid flag value for {flag}: '{p}'") - _flag_cache[s] = value + _flag_cache[cache_key] = value return value