summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@gmail.com>2014-09-06 17:21:12 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2014-09-07 00:23:15 +0000
commit674cbbcd597d732bca5ac0e465d1a7162e416023 (patch)
tree6029f73b19554cc9ef3861754857825abe943623
parent83c934fe3432cb7ebe6417c50059102c87cedf94 (diff)
Cache the lines that are read instead of re-reading
With-in the parsed file we cache the contents of the file before it is converted to unicode and the contents of the file after it is converted to unicode so it seems better to follow this pattern and to also cache the raw lines (instead of re-reading) as well. Change-Id: Ic320a6c5517e513c88bdb4014d509a5791d85524
Notes
Notes (review): Verified+2: Jenkins Code-Review+2: Christian Berendt <berendt@b1-systems.de> Workflow+1: Joshua Harlow <harlowja@yahoo-inc.com> Submitted-by: Jenkins Submitted-at: Mon, 08 Sep 2014 17:30:04 +0000 Reviewed-on: https://review.openstack.org/119580 Project: stackforge/doc8 Branch: refs/heads/master
-rw-r--r--doc8/parser.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/doc8/parser.py b/doc8/parser.py
index aeffc2d..7a88520 100644
--- a/doc8/parser.py
+++ b/doc8/parser.py
@@ -35,6 +35,7 @@ class ParsedFile(object):
35 self._encoding = encoding 35 self._encoding = encoding
36 self._doc = None 36 self._doc = None
37 self._errors = None 37 self._errors = None
38 self._lines = None
38 self._extension = os.path.splitext(filename)[1] 39 self._extension = os.path.splitext(filename)[1]
39 40
40 @property 41 @property
@@ -72,12 +73,14 @@ class ParsedFile(object):
72 return self._doc 73 return self._doc
73 74
74 def lines_iter(self, remove_trailing_newline=True): 75 def lines_iter(self, remove_trailing_newline=True):
75 with open(self.filename, 'rb') as fh: 76 if self._lines is None:
76 for line in fh: 77 with open(self.filename, 'rb') as fh:
77 line = six.text_type(line, encoding=self.encoding) 78 self._lines = list(fh)
78 if remove_trailing_newline and line.endswith("\n"): 79 for line in self._lines:
79 line = line[0:-1] 80 line = six.text_type(line, encoding=self.encoding)
80 yield line 81 if remove_trailing_newline and line.endswith("\n"):
82 line = line[0:-1]
83 yield line
81 84
82 @property 85 @property
83 def extension(self): 86 def extension(self):