From 6d7cbd6d2f2cde1a5f389ed60426f4e643f9daeb Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Sun, 29 Apr 2012 19:55:34 -0700 Subject: [PATCH] get list of tmpl_* functions only once --- beets/library.py | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/beets/library.py b/beets/library.py index 6c58356cc..36ee05f7a 100644 --- a/beets/library.py +++ b/beets/library.py @@ -1376,9 +1376,8 @@ class DefaultTemplateFunctions(object): and the values are Python functions. """ out = {} - for key in dir(self): - if key.startswith(self._prefix): - out[key[len(self._prefix):]] = getattr(self, key) + for key in self._func_names: + out[key[len(self._prefix):]] = getattr(self, key) return out @staticmethod @@ -1426,17 +1425,6 @@ class DefaultTemplateFunctions(object): """ return unidecode(s) - def _memo_get(self, key): - """Get a memoized value. The key is any hashable Python object. - The memoization namespace is associated with the library. - Returns None if no value is available. - """ - return self.lib._memotable.get(key) - - def _memo_set(self, key, value): - """Set a memoized value for the key.""" - self.lib._memotable[key] = value - def tmpl_aunique(self, keys=None, disam=None): """Generate a string that is guaranteed to be unique among all albums in the library who share the same set of keys. A fields @@ -1500,3 +1488,8 @@ class DefaultTemplateFunctions(object): res = u' [{}]'.format(disam_value) self.lib._memotable[memokey] = res return res + +# Get the name of tmpl_* functions in the above class. +DefaultTemplateFunctions._func_names = \ + [s for s in dir(DefaultTemplateFunctions) + if s.startswith(DefaultTemplateFunctions._prefix)]