diff options
author | Lars Wirzenius <liw@liw.fi> | 2010-07-10 18:06:57 +1200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2010-07-10 18:06:57 +1200 |
commit | f1676f4f01e28873bd78cac2f3b09dc1e02dabfd (patch) | |
tree | 77c505cdd31b269162cc3fcf3537f8c525fcfb27 | |
parent | 033385f7d6f5f603d5f7d9816bb15ed2c3bcf334 (diff) | |
download | obnam-f1676f4f01e28873bd78cac2f3b09dc1e02dabfd.tar.gz |
Minor speedups.
-rw-r--r-- | obnamlib/store.py | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/obnamlib/store.py b/obnamlib/store.py index 314b4257..229bd16b 100644 --- a/obnamlib/store.py +++ b/obnamlib/store.py @@ -86,6 +86,7 @@ def require_started_generation(method): numeric_fields = [x for x in obnamlib.metadata_fields if x.startswith('st_')] string_fields = [x for x in obnamlib.metadata_fields if x not in numeric_fields] +all_fields = numeric_fields + string_fields num_numeric = len(numeric_fields) metadata_format = struct.Struct('!Q' + 'Q' * len(obnamlib.metadata_fields)) @@ -102,6 +103,14 @@ def encode_metadata(metadata): return metadata_format.pack(*fields) + string +def flagtonone(flags, values): + for i, value in enumerate(values): + if flags & (1 << i): + yield value + else: + yield None + + def decode_metadata(encoded): buf = buffer(encoded) items = metadata_format.unpack_from(buf) @@ -116,14 +125,7 @@ def decode_metadata(encoded): append(encoded[offset:offset + length]) offset += length - def flagtonone(values): - for i, value in enumerate(values): - if flags & (1 << i): - yield value - else: - yield None - - args = dict(zip(numeric_fields + string_fields, flagtonone(values))) + args = dict(zip(all_fields, flagtonone(flags, values))) return obnamlib.Metadata(**args) |