diff options
author | Eevee (Alex Munroe) <amunroe@yelp.com> | 2014-03-24 18:00:17 -0700 |
---|---|---|
committer | Eevee (Alex Munroe) <amunroe@yelp.com> | 2014-07-01 17:33:00 -0700 |
commit | 53013fa01f45114c1b8ee87527eab4fbeef8a113 (patch) | |
tree | d4ea5d9e01a4e746ea48037443a62bdb40d250da /mixins.py | |
parent | 2e13d989dbf9a097c679e4e1ca71e59fc9e5524f (diff) | |
download | astroid-git-53013fa01f45114c1b8ee87527eab4fbeef8a113.tar.gz |
Speed up rebuilder considerably by computing line numbers lazily.
Fetching the last child of each of hundreds of thousands of nodes is
relatively expensive, and most of the time this information is never
used, so don't actually figure it out until it's asked for. Saves the
overhead of quite a few function calls, too.
Diffstat (limited to 'mixins.py')
-rw-r--r-- | mixins.py | 10 |
1 files changed, 6 insertions, 4 deletions
@@ -18,16 +18,18 @@ """This module contains some mixins for the different nodes. """ +from logilab.common.decorators import cachedproperty + from astroid.exceptions import (AstroidBuildingException, InferenceError, NotFoundError) class BlockRangeMixIn(object): """override block range """ - def set_line_info(self, lastchild): - self.fromlineno = self.lineno - self.tolineno = lastchild.tolineno - self.blockstart_tolineno = self._blockstart_toline() + + @cachedproperty + def blockstart_tolineno(self): + return self.lineno def _elsed_block_range(self, lineno, orelse, last=None): """handle block line numbers range for try/finally, for, if and while |