| | 382 | |
| | 383 | def simple_memoize(callable_object): |
| | 384 | """Simple memoization for functions without keyword arguments. |
| | 385 | |
| | 386 | This is useful for mapping code objects to module in this context. |
| | 387 | inspect.getmodule() requires a number of system calls, which may slow down |
| | 388 | the tracing considerably. Caching the mapping from code objects (there is |
| | 389 | *one* code object for each function, regardless of how many simultaneous |
| | 390 | activations records there are). |
| | 391 | |
| | 392 | In this context we can ignore keyword arguments, but a generic memoizer |
| | 393 | ought to take care of that as well. |
| | 394 | """ |
| | 395 | |
| | 396 | cache = dict() |
| | 397 | def wrapper(*rest): |
| | 398 | if rest not in cache: |
| | 399 | cache[rest] = callable_object(*rest) |
| | 400 | return cache[rest] |
| | 401 | |
| | 402 | return wrapper |
| | 403 | |
| | 404 | |