From a85e0523f8896bbc602b29f8b04836817babf6ef Mon Sep 17 00:00:00 2001 From: Yacine Elhamer Date: Tue, 1 Aug 2023 20:09:42 +0100 Subject: [PATCH] remove `Scopes` LRU caching --- capa/helpers.py | 19 ------------------- capa/rules/__init__.py | 6 +----- 2 files changed, 1 insertion(+), 24 deletions(-) diff --git a/capa/helpers.py b/capa/helpers.py index b47d9852..07234c22 100644 --- a/capa/helpers.py +++ b/capa/helpers.py @@ -132,25 +132,6 @@ def redirecting_print_to_tqdm(disable_progress): inspect.builtins.print = old_print # type: ignore -def weak_lru(maxsize=128, typed=False): - """ - LRU Cache decorator that keeps a weak reference to 'self' - """ - - def wrapper(func): - @functools.lru_cache(maxsize, typed) - def _func(_self, *args, **kwargs): - return func(_self(), *args, **kwargs) - - @functools.wraps(func) - def inner(self, *args, **kwargs): - return _func(weakref.ref(self), *args, **kwargs) - - return inner - - return wrapper - - def log_unsupported_format_error(): logger.error("-" * 80) logger.error(" Input file does not appear to be a PE or ELF file.") diff --git a/capa/rules/__init__.py b/capa/rules/__init__.py index 60af9ed5..ad669049 100644 --- a/capa/rules/__init__.py +++ b/capa/rules/__init__.py @@ -16,7 +16,7 @@ import collections from enum import Enum from pathlib import Path -from capa.helpers import weak_lru, assert_never +from capa.helpers import assert_never try: from functools import lru_cache @@ -115,10 +115,6 @@ class Scopes: static: Optional[str] = None dynamic: Optional[str] = None - @weak_lru() - def __new__(cls, *args, **kwargs): - return super().__new__(cls) - def __contains__(self, scope: Union[Scope, str]) -> bool: assert isinstance(scope, (Scope, str)) return (scope == self.static) or (scope == self.dynamic)