Commit Graph

82 Commits

Author SHA1 Message Date
Raymond Hettinger d8d6010df3 Sync-up with 3.4 to make maintenance easier. 2013-03-08 23:01:07 -08:00
Raymond Hettinger f96b2b03bb Improve comments and variable names. 2013-03-08 21:11:55 -07:00
Raymond Hettinger 352cc8cfc3 Another nit. 2013-03-04 04:19:09 -05:00
Raymond Hettinger f2c17a9276 Fix other re-entrancy nits for the lru_cache.
Keep references for oldkey and oldvalue so they can't
trigger a __del__ method to reenter our thread.

Move the cache[key]=link step to the end, after the link
data is in a consistent state.

Under exotic circumstances, the cache[key]=link step could
trigger reentrancy (i.e. the key would have to have a hash
exactly equal to that for another key in the cache and the
key would need a __eq__ method that makes a reentrant call
our cached function).
2013-03-04 03:34:09 -05:00
Raymond Hettinger 409f663091 Remove dependency on dummy_threading (to solve a bootstrap problem). 2013-03-01 23:20:13 -08:00
Raymond Hettinger fd54117a68 Don't deadlock on a reentrant call. 2013-03-01 03:47:57 -08:00
Raymond Hettinger 0c9050c25d Separate key creation logic from the sequence class that memoizes its hash value. 2012-06-04 00:21:14 -07:00
Raymond Hettinger 010ce3283a Minor change to default lru size. Set default to a power of two. 2012-05-19 21:20:48 -07:00
Raymond Hettinger 9acbb6074f Move make_key() out of the decorator body. Make keys that only need to be hashed once. 2012-04-30 22:32:16 -07:00
Raymond Hettinger 018b4fbb9b Use a flag to indicate when the circular queue is fully populated and stable. 2012-04-30 20:48:55 -07:00
Raymond Hettinger 34d94a2101 Handle a possible race condition 2012-04-30 14:14:28 -07:00
Raymond Hettinger b6b98c093e Track the cache size directly. 2012-04-29 18:09:02 -07:00
Raymond Hettinger 9f0ab9f564 Factor out shared variables. 2012-04-29 14:55:27 -07:00
Raymond Hettinger 678e7f3be6 Flatten the lru cache keyword args tuple for better memory utilization. 2012-04-29 12:28:02 -07:00
Raymond Hettinger c6897854f8 Fix-up a comment 2012-03-31 02:19:06 -07:00
Raymond Hettinger 7f7a5a7b87 Fix-up comments and add a sentinel variable for clarity. 2012-03-30 21:50:40 -07:00
Raymond Hettinger 41eb79a016 No need to create and destroy links when updating a fixed-sized circular queue. 2012-03-30 19:15:18 -07:00
Raymond Hettinger 1ff50df8bc Minor cleanup: add whitespace, add comments, bring function attribute updates together. 2012-03-30 13:15:48 -07:00
Raymond Hettinger 7dabfede34 Fix whitespace 2012-03-17 15:11:09 -07:00
Raymond Hettinger 7e0c581c49 Low overhead path for maxsize==0 2012-03-17 15:10:24 -07:00
Raymond Hettinger bc8e81dcc3 Section-off the source for better readability. 2012-03-17 00:24:09 -07:00
Raymond Hettinger dce583e0bd Minor beautification. 2012-03-16 22:12:20 -07:00
Raymond Hettinger 4f5139ba20 Root variable is not changed. 2012-03-16 17:08:37 -07:00
Raymond Hettinger 202d1ad3f6 Fix whitespace 2012-03-16 17:05:17 -07:00
Raymond Hettinger d37fb55910 Unique sentinel value for cache.get() 2012-03-16 17:04:11 -07:00
Raymond Hettinger 6e8c817687 Refactor calculation of the cache key. Minor code cleanups. 2012-03-16 16:53:05 -07:00
Benjamin Peterson 29a837d857 merge heads 2012-03-16 18:22:53 -05:00
Benjamin Peterson 954cf578c7 clear the root with the cache 2012-03-16 18:22:26 -05:00
Raymond Hettinger d656958915 Minor code cleanup. 2012-03-16 11:48:12 -07:00
Raymond Hettinger 57b2959d26 Eliminate duplicate link lookup. Minor cleanup. 2012-03-16 11:21:39 -07:00
Raymond Hettinger ec0e91045e Improve the memory utilization (and speed) of functools.lru_cache(). 2012-03-16 01:16:31 -07:00
Meador Inge ff7f64ca0e Issue #13544: Add __qualname__ to functools.WRAPPER_ASSIGNMENTS.
Patch by Filip Gruszczyński.
2011-12-11 22:37:31 -06:00
Raymond Hettinger cd9fdfd652 Issue 13227: Option to make the lru_cache() type specific (suggested by Andrew Koenig). 2011-10-20 08:57:45 -07:00
Raymond Hettinger d8886fc831 Merge 2011-10-16 00:00:51 -07:00
Raymond Hettinger 4b779b3785 Issue 13177: Make tracebacks more readable by avoiding chained exceptions in the lru_cache. 2011-10-15 23:50:42 -07:00
Raymond Hettinger 8cd2e5f751 Sync-up minor code edits with the default branch. 2011-05-05 14:15:12 -07:00
Raymond Hettinger e7a2430dde Fix __hash__ in functools.cmp_to_key() to work with collections.Hashable. 2011-05-03 11:16:36 -07:00
Raymond Hettinger 003be52932 Fix __hash__ in functools.cmp_to_key() to work with collections.Hashable. 2011-05-03 11:01:32 -07:00
Raymond Hettinger 7ab9e22e34 Issue #11707: Fast C version of functools.cmp_to_key() 2011-04-05 02:33:54 -07:00
Raymond Hettinger 0a4edd5435 Issue #11628: cmp_to_key should use __slots__. 2011-03-21 17:54:04 -07:00
Raymond Hettinger a0d1d96771 Issue #11628: cmp_to_key should use __slots__. 2011-03-21 17:50:28 -07:00
Raymond Hettinger 7e4c168385 Minor optimization -- factor a constant expression out of the inner-loop. 2011-03-18 15:09:10 -07:00
Raymond Hettinger 524359f9f7 Add comment. 2011-01-11 22:08:55 +00:00
Raymond Hettinger 23f9fc3448 Issue #10042: Fixed the total_ordering decorator to handle cross-type
comparisons that could lead to infinite recursion.
2011-01-08 07:01:56 +00:00
Raymond Hettinger c79fb0e52d Issue 10593: Adopt Nick's suggestion for an lru_cache with maxsize=None. 2010-12-01 03:45:41 +00:00
Raymond Hettinger 00f2f97dbd Doc and docstring nits. 2010-12-01 00:47:56 +00:00
Raymond Hettinger 7496b4171e Add example, tighten text, and minor clean-ups. 2010-11-30 19:15:45 +00:00
Raymond Hettinger 5e20bab422 Neaten-up a bit. 2010-11-30 07:13:04 +00:00
Nick Coghlan 234515afe5 Issue 10586: change the new functools.lru_cache implementation to expose the maximum and current cache sizes through the public statistics API. This API is now a single function that returns a named tuple. 2010-11-30 06:19:46 +00:00
Raymond Hettinger 5fa40c01ad Clean-up docstring, comments, and whitespace. 2010-11-25 08:11:57 +00:00