From ffb4b3eb3de75f53a92cbfe16473ab8c1461ea94 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sat, 21 Jul 2012 07:56:49 -0400 Subject: [PATCH] Avoid expensive pformating in DynamicStructure.unpack_stream unless required. If we're not going to be printing the formatted data in the log, don't bother calculating it. On my system, this speeds up the loading of polar-graphs-demo.pxp by a factor of 10. --- igor/struct.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/igor/struct.py b/igor/struct.py index fce93b5..ea8af34 100644 --- a/igor/struct.py +++ b/igor/struct.py @@ -717,7 +717,8 @@ class DynamicStructure (Structure): for f in self.fields: _LOG.debug('parsing {!r}.{} (count={}, item_count={})'.format( self, f, f.count, f.item_count)) - _LOG.debug('data:\n{}'.format(_pprint.pformat(data))) + if _LOG.level <= _logging.DEBUG: + _LOG.debug('data:\n{}'.format(_pprint.pformat(data))) if hasattr(f, 'pre_unpack'): _LOG.debug('pre-unpack {}'.format(f)) f.pre_unpack(parents=parents, data=data) -- 2.26.2