From b8d0940b31f1f77d19a17f2e30c5206ad4f9e7f9 Mon Sep 17 00:00:00 2001 From: "g@localhost.localdomain" Date: Tue, 21 Nov 2006 23:42:51 +0100 Subject: [PATCH] Use setdefault() instead of reinventing it --- pysize/core/pysize_global_fs_cache.py | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/pysize/core/pysize_global_fs_cache.py b/pysize/core/pysize_global_fs_cache.py index cc017d2..006c627 100644 --- a/pysize/core/pysize_global_fs_cache.py +++ b/pysize/core/pysize_global_fs_cache.py @@ -38,16 +38,9 @@ def get_dev_ino(path): st = os.lstat(path) return st.st_dev, st.st_ino -def _get_inodes(table, dev): - inodes = table.get(dev, None) - if not inodes: - inodes = {} - table[dev] = inodes - return inodes - def cache_add_dir((dev, ino), size): """Add a directory and its size to the cache.""" - inodes = _get_inodes(DEV_DIR_SIZE, dev) + inodes = DEV_DIR_SIZE.setdefault(dev, {}) inodes[ino] = size def cache_add_hardlink(dev, ino, dir_ino, basename): @@ -55,11 +48,8 @@ def cache_add_hardlink(dev, ino, dir_ino, basename): location should be considered as the canonical location. Unlike for the canonical location, a hardlink size is 0.""" entry = dir_ino, basename - inodes = _get_inodes(DEV_HLINK_DNAME, dev) - cached_entry = inodes.get(ino, None) - if not cached_entry: - inodes[ino] = entry - return True + inodes = DEV_HLINK_DNAME.setdefault(dev, {}) + cached_entry = inodes.setdefault(ino, entry) return cached_entry == entry def cache_get_dir_size((dev, ino)): -- 2.11.4.GIT