diff options
author | Lars Wirzenius <liw@liw.fi> | 2015-11-01 13:34:49 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2015-11-01 13:34:49 +0200 |
commit | a0a793977eb7da818ee0d3249785ae3c101dddea (patch) | |
tree | 8a92283f647aa1b4c75e3aced489f86268db2fa4 | |
parent | 4e8f0da498b7e8cb298403136f155de0dbc0a53d (diff) | |
download | obnam-a0a793977eb7da818ee0d3249785ae3c101dddea.tar.gz |
Set a GADirectory's contents as one dict
We store on disk a dict that is the same dict we keep in memory.
Previously we were unpacking the from-disk dict and setting each item
individually in a new dict, resulting an identical dict, and some CPU
time being spent. This should speed things up a bit.
-rw-r--r-- | obnamlib/fmt_ga/dirobj.py | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/obnamlib/fmt_ga/dirobj.py b/obnamlib/fmt_ga/dirobj.py index b7f0915f..e98019bd 100644 --- a/obnamlib/fmt_ga/dirobj.py +++ b/obnamlib/fmt_ga/dirobj.py @@ -37,6 +37,9 @@ class GADirectory(object): def as_dict(self): return self._dict + def set_from_dict(self, a_dict): + self._dict = a_dict + def add_file(self, basename): self._require_mutable() self._dict['metadata'][basename] = { @@ -98,10 +101,5 @@ class GAImmutableError(obnamlib.ObnamError): def create_gadirectory_from_dict(a_dict): dir_obj = GADirectory() - for basename in a_dict['metadata']: - dir_obj.add_file(basename) - for key, value in a_dict['metadata'][basename].items(): - dir_obj.set_file_key(basename, key, value) - for subdir, obj_id in a_dict['subdirs'].items(): - dir_obj.add_subdir(subdir, obj_id) + dir_obj.set_from_dict(a_dict) return dir_obj |