Avoid expensive pformating in DynamicStructure.unpack_stream unless required.
authorW. Trevor King <wking@tremily.us>
Sat, 21 Jul 2012 11:56:49 +0000 (07:56 -0400)
committerW. Trevor King <wking@tremily.us>
Sat, 21 Jul 2012 11:56:49 +0000 (07:56 -0400)
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

index fce93b56798f74e07dc14c1e999b411bf852c802..ea8af34dfd2b1b492c6e29c216a9bbf9dace9f17 100644 (file)
@@ -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)