| Index: mojo/tools/mopy/memoize.py
|
| diff --git a/mojo/tools/mopy/memoize.py b/mojo/tools/mopy/memoize.py
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..249440b35adcb149b3b685e11a3e097ced6f8cdb
|
| --- /dev/null
|
| +++ b/mojo/tools/mopy/memoize.py
|
| @@ -0,0 +1,18 @@
|
| +# Copyright 2014 The Chromium Authors. All rights reserved.
|
| +# Use of this source code is governed by a BSD-style license that can be
|
| +# found in the LICENSE file.
|
| +
|
| +import sys
|
| +
|
| +# pylint: disable=C0301
|
| +# Based on/taken from
|
| +# http://code.activestate.com/recipes/578231-probably-the-fastest-memoization-decorator-in-the-/
|
| +# (with cosmetic changes).
|
| +# pylint: enable=C0301
|
| +def memoize(f):
|
| + """Memoization decorator for a function taking a single argument."""
|
| + class Memoize(dict):
|
| + def __missing__(self, key):
|
| + rv = self[key] = f(key)
|
| + return rv
|
| + return Memoize().__getitem__
|
|
|