##// END OF EJS Templates
bufferedinputpipe: remove N^2 computation of buffer length (issue4735)...
Pierre-Yves David -
r25672:050dc6ea default
parent child Browse files
Show More
@@ -254,6 +254,7 b' class bufferedinputpipe(object):'
254 self._input = input
254 self._input = input
255 self._buffer = []
255 self._buffer = []
256 self._eof = False
256 self._eof = False
257 self._lenbuf = 0
257
258
258 @property
259 @property
259 def hasbuffer(self):
260 def hasbuffer(self):
@@ -283,6 +284,7 b' class bufferedinputpipe(object):'
283 # this should not happen because both read and readline end with a
284 # this should not happen because both read and readline end with a
284 # _frombuffer call that collapse it.
285 # _frombuffer call that collapse it.
285 self._buffer = [''.join(self._buffer)]
286 self._buffer = [''.join(self._buffer)]
287 self._lenbuf = len(self._buffer[0])
286 lfi = -1
288 lfi = -1
287 if self._buffer:
289 if self._buffer:
288 lfi = self._buffer[-1].find('\n')
290 lfi = self._buffer[-1].find('\n')
@@ -298,11 +300,6 b' class bufferedinputpipe(object):'
298 size += self._lenbuf - len(self._buffer[-1])
300 size += self._lenbuf - len(self._buffer[-1])
299 return self._frombuffer(size)
301 return self._frombuffer(size)
300
302
301 @property
302 def _lenbuf(self):
303 """return the current lengh of buffered data"""
304 return sum(len(d) for d in self._buffer)
305
306 def _frombuffer(self, size):
303 def _frombuffer(self, size):
307 """return at most 'size' data from the buffer
304 """return at most 'size' data from the buffer
308
305
@@ -317,8 +314,10 b' class bufferedinputpipe(object):'
317 buf = buf[len(data):]
314 buf = buf[len(data):]
318 if buf:
315 if buf:
319 self._buffer = [buf]
316 self._buffer = [buf]
317 self._lenbuf = len(buf)
320 else:
318 else:
321 self._buffer = []
319 self._buffer = []
320 self._lenbuf = 0
322 return data
321 return data
323
322
324 def _fillbuffer(self):
323 def _fillbuffer(self):
@@ -327,6 +326,7 b' class bufferedinputpipe(object):'
327 if not data:
326 if not data:
328 self._eof = True
327 self._eof = True
329 else:
328 else:
329 self._lenbuf += len(data)
330 self._buffer.append(data)
330 self._buffer.append(data)
331
331
332 def popen2(cmd, env=None, newlines=False):
332 def popen2(cmd, env=None, newlines=False):
General Comments 0
You need to be logged in to leave comments. Login now