From d4a16537344c2f11ef518a36d9eef232218afd70 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Fri, 23 Apr 2010 16:21:35 -0400 Subject: [PATCH] vfs: cache file sizes in the Node object. Since the filesystem is read only, there's no reason to recalculate the file size every time someone asks :) --- lib/bup/vfs.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/bup/vfs.py b/lib/bup/vfs.py index 7964c98..91566da 100644 --- a/lib/bup/vfs.py +++ b/lib/bup/vfs.py @@ -142,6 +142,10 @@ class Node: class File(Node): + def __init__(self, parent, name, mode, hash): + Node.__init__(self, parent, name, mode, hash) + self._cached_size = None + def _content(self): return cp().join(self.hash.encode('hex')) @@ -151,7 +155,9 @@ class File(Node): def size(self): # FIXME inefficient. If a file is chunked, we could just check # the offset + size of the very last chunk. - return sum(len(blob) for blob in self._content()) + if self._cached_size == None: + self._cached_size = sum(len(blob) for blob in self._content()) + return self._cached_size def readbytes(self, ofs, count): # FIXME inefficient. If a file is chunked, we could choose to -- 2.39.2