diff options
| author | Barry Warsaw <barry@python.org> | 2000-10-05 18:48:12 (GMT) | 
|---|---|---|
| committer | Barry Warsaw <barry@python.org> | 2000-10-05 18:48:12 (GMT) | 
| commit | 293b03f73f5ad48719a0f07fb45857182dfb1d51 (patch) | |
| tree | 7ecbfac21738131ec43f5ae8c98947335055ddd6 /Lib/gettext.py | |
| parent | 7d1219d9bdb9598c95636daac741896f2167b09f (diff) | |
| download | cpython-293b03f73f5ad48719a0f07fb45857182dfb1d51.zip cpython-293b03f73f5ad48719a0f07fb45857182dfb1d51.tar.gz cpython-293b03f73f5ad48719a0f07fb45857182dfb1d51.tar.bz2  | |
translation(): Minor optimization patch which avoids instantiating the
default value's instance unless it's absolutely necessary.
Diffstat (limited to 'Lib/gettext.py')
| -rw-r--r-- | Lib/gettext.py | 6 | 
1 files changed, 5 insertions, 1 deletions
diff --git a/Lib/gettext.py b/Lib/gettext.py index 724cecb..578490f 100644 --- a/Lib/gettext.py +++ b/Lib/gettext.py @@ -235,7 +235,11 @@ def translation(domain, localedir=None, languages=None, class_=None):          raise IOError(ENOENT, 'No translation file found for domain', domain)      key = os.path.abspath(mofile)      # TBD: do we need to worry about the file pointer getting collected? -    t = _translations.setdefault(key, class_(open(mofile, 'rb'))) +    # Avoid opening, reading, and parsing the .mo file after it's been done +    # once. +    t = _translations.get(key) +    if t is None: +        t = _translations.setdefault(key, class_(open(mofile, 'rb')))      return t  | 
