Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 40029:e2697acd9381
cleanup: some Yoda conditions, this patch removes
It seems the factor 20 is less than the frequency of " < \d" compared
to " \d > ".
Differential Revision: https://phab.mercurial-scm.org/D4862
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Wed, 03 Oct 2018 10:27:44 -0700 |
parents | 4017968f0a1d |
children | 3c89227788a2 |
comparison
equal
deleted
inserted
replaced
40028:51f10e6d66c7 | 40029:e2697acd9381 |
---|---|
331 if not self._eof and self._lenbuf == 0: | 331 if not self._eof and self._lenbuf == 0: |
332 self._fillbuffer(max(size, _chunksize)) | 332 self._fillbuffer(max(size, _chunksize)) |
333 return self._frombuffer(min(self._lenbuf, size)) | 333 return self._frombuffer(min(self._lenbuf, size)) |
334 | 334 |
335 def readline(self, *args, **kwargs): | 335 def readline(self, *args, **kwargs): |
336 if 1 < len(self._buffer): | 336 if len(self._buffer) > 1: |
337 # this should not happen because both read and readline end with a | 337 # this should not happen because both read and readline end with a |
338 # _frombuffer call that collapse it. | 338 # _frombuffer call that collapse it. |
339 self._buffer = [''.join(self._buffer)] | 339 self._buffer = [''.join(self._buffer)] |
340 self._lenbuf = len(self._buffer[0]) | 340 self._lenbuf = len(self._buffer[0]) |
341 lfi = -1 | 341 lfi = -1 |
346 if self._buffer: | 346 if self._buffer: |
347 lfi = self._buffer[-1].find('\n') | 347 lfi = self._buffer[-1].find('\n') |
348 size = lfi + 1 | 348 size = lfi + 1 |
349 if lfi < 0: # end of file | 349 if lfi < 0: # end of file |
350 size = self._lenbuf | 350 size = self._lenbuf |
351 elif 1 < len(self._buffer): | 351 elif len(self._buffer) > 1: |
352 # we need to take previous chunks into account | 352 # we need to take previous chunks into account |
353 size += self._lenbuf - len(self._buffer[-1]) | 353 size += self._lenbuf - len(self._buffer[-1]) |
354 return self._frombuffer(size) | 354 return self._frombuffer(size) |
355 | 355 |
356 def _frombuffer(self, size): | 356 def _frombuffer(self, size): |
358 | 358 |
359 The data are removed from the buffer.""" | 359 The data are removed from the buffer.""" |
360 if size == 0 or not self._buffer: | 360 if size == 0 or not self._buffer: |
361 return '' | 361 return '' |
362 buf = self._buffer[0] | 362 buf = self._buffer[0] |
363 if 1 < len(self._buffer): | 363 if len(self._buffer) > 1: |
364 buf = ''.join(self._buffer) | 364 buf = ''.join(self._buffer) |
365 | 365 |
366 data = buf[:size] | 366 data = buf[:size] |
367 buf = buf[len(data):] | 367 buf = buf[len(data):] |
368 if buf: | 368 if buf: |