Chromium Code Reviews| Index: presubmit_support.py |
| =================================================================== |
| --- presubmit_support.py (revision 82587) |
| +++ presubmit_support.py (working copy) |
| @@ -12,6 +12,7 @@ |
| # caching (between all different invocations of presubmit scripts for a given |
| # change). We should add it as our presubmit scripts start feeling slow. |
| +import copy |
|
M-A Ruel
2011/04/23 01:05:03
not needed.
ncarter (slow)
2011/04/26 17:15:19
Done.
|
| import cPickle # Exposed through the API. |
| import cStringIO # Exposed through the API. |
| import fnmatch |
| @@ -396,7 +397,7 @@ |
| integer line number (1-based); and |
| the contents of the line as a string. |
| - Note: The cariage return (LF or CR) is stripped off. |
| + Note: The carriage return (LF or CR) is stripped off. |
| """ |
| files = self.AffectedSourceFiles(source_file_filter) |
| return _RightHandSideLinesImpl(files) |
| @@ -423,6 +424,8 @@ |
| self._local_root = repository_root |
| self._is_directory = None |
| self._properties = {} |
| + self._cached_changed_contents = None |
| + self._cached_new_contents = None |
| logging.debug('%s(%s)' % (self.__class__.__name__, self._path)) |
| def ServerPath(self): |
| @@ -475,13 +478,15 @@ |
| side". |
| Contents will be empty if the file is a directory or does not exist. |
| - Note: The cariage returns (LF or CR) are stripped off. |
| + Note: The carriage returns (LF or CR) are stripped off. |
| """ |
| - if self.IsDirectory(): |
| - return [] |
| - else: |
| - return gclient_utils.FileRead(self.AbsoluteLocalPath(), |
| - 'rU').splitlines() |
| + if self._cached_new_contents is None: |
| + if self.IsDirectory(): |
| + self._cached_new_contents = [] |
| + else: |
| + self._cached_new_contents = gclient_utils.FileRead( |
|
M-A Ruel
2011/04/23 01:05:03
It should trap IOError and set to []. The file cou
ncarter (slow)
2011/04/26 17:15:19
Done. Also, added unittest.
|
| + self.AbsoluteLocalPath(), 'rU').splitlines() |
| + return copy.deepcopy(self._cached_new_contents) |
|
M-A Ruel
2011/04/23 01:05:03
return self._cached_new_contents[:]
ncarter (slow)
2011/04/26 17:15:19
Of course. Done.
|
| def OldContents(self): |
| """Returns an iterator over the lines in the old version of file. |
| @@ -507,7 +512,9 @@ |
| ^@@ <old line num>,<old size> <new line num>,<new size> @@$ |
| """ |
| - new_lines = [] |
| + if self._cached_changed_contents is not None: |
| + return copy.deepcopy(self._cached_changed_contents) |
| + self._cached_changed_contents = [] |
| line_num = 0 |
| if self.IsDirectory(): |
| @@ -519,10 +526,10 @@ |
| line_num = int(m.groups(1)[0]) |
| continue |
| if line.startswith('+') and not line.startswith('++'): |
| - new_lines.append((line_num, line[1:])) |
| + self._cached_changed_contents.append((line_num, line[1:])) |
| if not line.startswith('-'): |
| line_num += 1 |
| - return new_lines |
| + return copy.deepcopy(self._cached_changed_contents) |
| def __str__(self): |
| return self.LocalPath() |