mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Improve performance on pre-commit -r pyflakes by 40%
This commit is contained in:
parent
356e4ba13b
commit
da8c435e9c
3 changed files with 59 additions and 5 deletions
|
|
@ -1,4 +1,8 @@
|
|||
|
||||
import functools
|
||||
import os
|
||||
|
||||
|
||||
class cached_property(object):
|
||||
"""Like @property, but caches the value."""
|
||||
|
||||
|
|
@ -14,3 +18,19 @@ class cached_property(object):
|
|||
value = self._func(obj)
|
||||
obj.__dict__[self.__name__] = value
|
||||
return value
|
||||
|
||||
|
||||
def memoize_by_cwd(func):
|
||||
"""Memoize a function call based on os.getcwd()."""
|
||||
cache = {}
|
||||
@functools.wraps(func)
|
||||
def wrapper(*args):
|
||||
cwd = os.getcwd()
|
||||
key = (cwd,) + args
|
||||
try:
|
||||
return cache[key]
|
||||
except KeyError:
|
||||
ret = cache[key] = func(*args)
|
||||
return ret
|
||||
|
||||
return wrapper
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue