diff options
author | TW <tw@waldmann-edv.de> | 2016-08-20 21:19:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-20 21:19:17 +0200 |
commit | 357f4ef72ed834534b603dae6bc8316d245d12ec (patch) | |
tree | 358397bf784d54456acda4404858d21d579b78fb /src | |
parent | 12ea5d01cbad16a7a044452677124e48d213e669 (diff) | |
parent | 61af307ad4bb317503b1eb3ee60f7421881e5f5d (diff) |
Merge pull request #1511 from c4rlo/lru-cache
helpers.py: replace memoize with functools.lru_cache
Diffstat (limited to 'src')
-rw-r--r-- | src/borg/helpers.py | 23 |
1 files changed, 5 insertions, 18 deletions
diff --git a/src/borg/helpers.py b/src/borg/helpers.py index d6237c5be..6751285d8 100644 --- a/src/borg/helpers.py +++ b/src/borg/helpers.py @@ -22,7 +22,7 @@ from collections import namedtuple, deque, abc from contextlib import contextmanager from datetime import datetime, timezone, timedelta from fnmatch import translate -from functools import wraps, partial +from functools import wraps, partial, lru_cache from itertools import islice from operator import attrgetter from string import Formatter @@ -722,19 +722,6 @@ def format_archive(archive): ) -def memoize(function): - cache = {} - - def decorated_function(*args): - try: - return cache[args] - except KeyError: - val = function(*args) - cache[args] = val - return val - return decorated_function - - class Buffer: """ provide a thread-local buffer @@ -776,7 +763,7 @@ class Buffer: return self._thread_local.buffer -@memoize +@lru_cache(maxsize=None) def uid2user(uid, default=None): try: return pwd.getpwuid(uid).pw_name @@ -784,7 +771,7 @@ def uid2user(uid, default=None): return default -@memoize +@lru_cache(maxsize=None) def user2uid(user, default=None): try: return user and pwd.getpwnam(user).pw_uid @@ -792,7 +779,7 @@ def user2uid(user, default=None): return default -@memoize +@lru_cache(maxsize=None) def gid2group(gid, default=None): try: return grp.getgrgid(gid).gr_name @@ -800,7 +787,7 @@ def gid2group(gid, default=None): return default -@memoize +@lru_cache(maxsize=None) def group2gid(group, default=None): try: return group and grp.getgrnam(group).gr_gid |